Below code uses System.Net.Ftpwebrequest package in AX to integrate with FTP. This job demonstrates how to read a file from FTP folder. Refer WebRequestMethods.Ftp Class for different actions.
static void FTPReadFile(Args _args)
{
System.Object ftpo;
System.Net.FtpWebRequest request;
System.IO.StreamReader reader;
System.IO.StreamWriter writer;
System.IO.Stream responseStream;
System.Net.NetworkCredential credential;
System.Net.FtpWebResponse response;
System.Net.WebRequestMethods methods;
str fileContent;
List ftpFileList;
;
ftpo = System.Net.WebRequest::Create("ftp://ftp.url.com/foldername/filename.txt");
request = ftpo;
credential = new System.Net.NetworkCredential("username", "password");
request.set_Credentials(credential);
request.set_Method("RETR");
request.set_UsePassive(true);
request.set_UseBinary(true);
request.set_KeepAlive(false);
response = request.GetResponse();
responseStream = response.GetResponseStream();
reader = new System.IO.StreamReader(responseStream);
fileContent = reader.ReadToEnd();
reader.Close();
responseStream.Close();
response.Close();
}
Regards,
K.
Arunsubramaniam
No comments:
Post a Comment