FTP upload using .Net
Do you create files in NAV that you upload to an FTP site? Did you know that you can control the FTP upload from C/AL code using .Net? You can use the code below as a starting point to create your own solution. This way you don’t have to install any 3rd party FTP-software and you can get full full in NAV. Download is very similar to the code below. You can find more information on the FTP library in .Net here.
Name DataType Subtype Length FTPRequest DotNet System.Net.FtpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Credentials DotNet System.Net.NetworkCredential.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' FileStream DotNet System.IO.FileStream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Stream DotNet System.IO.Stream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' File DotNet System.IO.File.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' FTPRequest := FTPRequest.Create(FTP_Address_Variable + Filename_Variable); Credentials := Credentials.NetworkCredential(FTP_Username_Variable, FTP_Password_Variable); FTPRequest.Credentials := Credentials; FTPRequest.KeepAlive := TRUE; FTPRequest.Method := 'STOR'; FTPRequest.UsePassive := TRUE; FTPRequest.UseBinary := TRUE; FileStream := File.OpenRead(Pat_Variable + Filename_Variable); Stream := FTPRequest.GetRequestStream; FileStream.CopyTo(Stream); Stream.Close; FileStream.Close;
No comments yet.