Options

FTP upload + NAV2017

JavaidJavaid Member Posts: 23
edited 2022-03-26 in NAV Three Tier
Hi

I want to upload *.csv files to a specifik ftp folder and I have found some code, that I do not understand. Can someone help me?

FTPSetup.SETRANGE("FTP Active",TRUE);
IF FTPSetup.FINDSET THEN
REPEAT
URL := FTPSetup."FTP Server" + ' ';
URL += FTPSetup."Path to Files"+'/' + 'de-int2c5-05012021.csv';


FTPRequest := WebRequest.Create(URL);

FTPRequest.Credentials := Credentials.NetworkCredential(FTPSetup."User ID",FTPSetup.Password);

FTPRequest.KeepAlive := FALSE;
FTPRequest.UseBinary := TRUE;
FTPRequest.Method := 'STOR';
FTPRequest.UsePassive := TRUE;

FileStream := FileA.OpenRead(FTPSetup."Path to Files"+'/' + 'de-int2c5-05012021.csv');
FTPRequest.GetRequestStream.Write(FileA.ReadAllBytes(FTPSetup."Path to Files"+'/' + 'de-int2c5-05012021.csv'), 0, FileStream.Length);

UNTIL FTPSetup.NEXT = 0;

Is the above code right to use to FTP upload?

Best Recards
Javaid



Best Answer

Answers

  • Options
    SanderDkSanderDk Member Posts: 497
    Perhaps this code can help you
    This is code that can upload a file to a FTP site:
    FtpWebRequest             := WebRequest.Create(FTPAdress + FileManagement.GetFileName(FullFilepath));
          Credentials               := Credentials.NetworkCredential(Username,Password);
          FtpWebRequest.Credentials := Credentials;
    
          FtpWebRequest.KeepAlive   := FALSE;
          FtpWebRequest.UseBinary   := TRUE;
          FtpWebRequest.UsePassive  := Passiv;
          FtpWebRequest.Method('STOR');
    
          FileStream                := FileToUpload.OpenRead(FullFilepath);
          Stream                    := FtpWebRequest.GetRequestStream;
          Stream.Write(FileToUpload.ReadAllBytes(FullFilepath),0,FileStream.Length);
          Stream.Close;
          FtpWebResponse            := FtpWebRequest.GetResponse;
          FileStream.Close;
          FtpWebRequest.Abort;
    
         //Get Status of Upload with  
         //MESSAGE(FORMAT(FtpWebResponse.StatusDescription))
    
    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
  • Options
    JavaidJavaid Member Posts: 23
    Hi

    Thanks. I have some questions.

    pkm4jbdcuwb8.png

    Mark with green: This is the full path to the file I will upload.

    Mark with yellow: What is passive? Can it be false?

    499gn4z6gqqm.png

    I will move the file to the FTP folder Mask_0295. Where do I mention this in the code?



  • Options
    SanderDkSanderDk Member Posts: 497
    Answer ✓
    The path marked with green looks good

    Active and passive:
    Yes it can, it depends on the FTP server you can read more about active/passive here: https://www.jscape.com/blog/bid/80512/active-v-s-passive-ftp-simplified
    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
  • Options
    JJMcJJMc Member Posts: 59
    Hi.

    Could you please, tell me what king of variables are those used in this peace of code?

    Thank you ever so much
  • Options
    JavaidJavaid Member Posts: 23
    This problem is solved.

    Thanks to everyone.
  • Options
    SanderDkSanderDk Member Posts: 497
    JJMc wrote: »
    Could you please, tell me what king of variables are those used in this peace of code?
      FtpWebRequest@1160810003 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.FtpWebRequest";
          WebRequest@1160810005 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebRequest";
          Credentials@1160810004 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.NetworkCredential";
          FileStream@1160810010 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileStream";
          FileToUpload@1160810011 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.File";
          Stream@1160810001 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream";
          FileManagement@1160810006 : Codeunit 419;
          FtpWebResponse@1160810012 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.FtpWebResponse";
    
    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
  • Options
    JJMcJJMc Member Posts: 59
    SanderDk wrote: »
    JJMc wrote: »
    Could you please, tell me what king of variables are those used in this peace of code?
      FtpWebRequest@1160810003 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.FtpWebRequest";
          WebRequest@1160810005 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.WebRequest";
          Credentials@1160810004 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.NetworkCredential";
          FileStream@1160810010 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileStream";
          FileToUpload@1160810011 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.File";
          Stream@1160810001 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream";
          FileManagement@1160810006 : Codeunit 419;
          FtpWebResponse@1160810012 : DotNet "'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.FtpWebResponse";
    

    Thank you ever so much
  • Options
    krikikriki Member, Moderator Posts: 9,096
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.