NAV2013 FTP without Libraries

AdministratorAdministrator Member, Moderator, Administrator Posts: 2,500
edited 2014-11-11 in Download section
NAV2013 FTP without Libraries
No need of DLL. RAW FTP commands implementation with .NET 4.
This lib was tested with 2013 both NAS and RTC. After some magic should also work on 2009 RTC. Use and enjoy :)

Functions:
GetFilesList, UploadFile, UploadFiles, DownloadFile, DownloadFiles

Easy-to use, .NET Framework only based, no need of additional software or whatever.

http://www.mibuso.com/dlinfo.asp?FileID=1539

Discuss this download here.

Comments

  • androjdazandrojdaz Member Posts: 20
    Awesome! Checked, works great! Thanks
    That's what she said!
  • wakestarwakestar Member Posts: 207
    I think this solution works as long as you don't get any .net exceptions right?
  • Igor_PchelnikovIgor_Pchelnikov Member Posts: 25
    Hello,
    these functions don't have any exceptions handling parts.

    Igor Pchelnikov
  • vremeni4vremeni4 Member Posts: 323
    Hi,

    Just wanted to say thank you for this upload. You saved me a lot of time.
    Especially the idea to use
    ResponseStream.CopyTo(SimpleStream);
    on FTP download function was very helpful. =D> =D> =D>

    Thanks.
  • mrQQmrQQ Member Posts: 239
    yeah, it was tricky to write the file to ftp request :)
  • chrisdfchrisdf Member Posts: 82
    Hi,

    Firstly thanks for sharing this utility :D

    When using this, we get occasional errors from the GetRequestStream method e.g.

    A call to System.Net.FtpWebRequest.GetRequestStream failed with this message: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
    A call to System.Net.FtpWebRequest.GetRequestStream failed with this message: Unable to connect to the remote server

    This is running on a NAV2013 NAS and gives an error which halts the job that is set to run every 60 minutes.

    Could you offer any advise on how to code around this error so that it doesn't error the Job Queue Entry if it happens? i.e. what could I test before running GetRequestStream ??

    Using the libraries as per your download - not changed anything.

    Thanks!
  • vremeni4vremeni4 Member Posts: 323
    Hi,

    I think you can use the option to check the return value of the codeunit
    IF CODEUNIT.RUN(CODEUNIT::"FTP send") THEN BEGIN

    END ELSE BEGIN
    //ignore if there is an error or use lasterrormsg and write in the job queue log
    END;

    I hope this helps.

    Thanks.
  • clemboclembo Member Posts: 122
    When using I get an error: The uri prefix was not recognized.
    Why?
  • madsmorremadsmorre Member Posts: 40
    Hi
    I get the following error - any ideas?
    dxpu8adkydbg.png

    Here is the code

    //Call to Codeunit ()
    ToFile := FileMan.ServerTempFileName('csv');
    v_ExpFile.CREATE(ToFile);
    v_ExpFile.TEXTMODE(TRUE);
    CreateHeader; //Put in header information
    CreateData; //Put in Line information
    v_ExpFile.CLOSE;
    FTPHandling2.UploadFile("FileName",'ftp://xxxxxx.dk/"Foldername"/',"LOGIN","Password");

    Actual FTP-codeunit
    UploadFile(FileNameToUpload : Text;UploadToFtp : Text;Login : Text;Password : Text)
    FTPRequest := FTPRequest.Create(UploadToFtp);
    Credentials := Credentials.NetworkCredential(Login,Password);
    FTPRequest.Credentials := Credentials;
    FTPRequest.KeepAlive := TRUE;
    FTPRequest.Method := 'STOR';
    FTPRequest.UsePassive := TRUE;
    FTPRequest.UseBinary := TRUE;
    RealFileStream := FileStream.OpenRead(FileNameToUpload);
    SimpleStream := FTPRequest.GetRequestStream;
    RealFileStream.CopyTo(SimpleStream);
    SimpleStream.Close;
    RealFileStream.Close;
  • madsmorremadsmorre Member Posts: 40
    Issue solved - i needed the "to be" filename in the url.
  • shanabeywicremashanabeywicrema Member Posts: 53
    Hi All,
    I am getting this error when call the uploadfile

    This message is for C/AL programmers: A call to System.Net.FtpWebRequest.Create failed with this message: Invalid URI: The format of the URI could not be determined.

    This is how I pass the parameters
    UploadFile('E:\Bin\shan.txt','ftp.mydomain.com','user','pass');
  • foo_barfoo_bar Member Posts: 91
    try with the following
    UploadFile('E:\Bin\shan.txt','ftp://ftp.mydomain.com','user','pass');
  • shanabeywicremashanabeywicrema Member Posts: 53
    When I try it, its giving me this error

    Microsoft Dynamics NAV

    This message is for C/AL programmers: A call to System.Net.FtpWebRequest.GetRequestStream failed with this message: The remote name could not be resolved: 'ftp.mydomain.com'
    OK
  • irasoelbaksirasoelbaks Member Posts: 119
    When I try it, its giving me this error

    Microsoft Dynamics NAV

    This message is for C/AL programmers: A call to System.Net.FtpWebRequest.GetRequestStream failed with this message: The remote name could not be resolved: 'ftp.mydomain.com'
    OK

    The error is quite clear in my opinion? Looks like you are trying to connect to server: ftp.mydomain.com. Is an FTP service listening at this domain name?
Sign In or Register to comment.