Below code uses System.Net.Ftpwebrequest package in AX to integrate with FTP. This job demonstrates how to list the file names from FTP folder. Refer WebRequestMethods.Ftp Class for different actions.
static void FTPFileList(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 text;
List ftpFileList;
;
ftpo = System.Net.WebRequest::Create("ftp://ftp.url.com/foldername/*.txt");
request = ftpo;
credential = new System.Net.NetworkCredential("username", "password");
request.set_Credentials(credential);
request.set_Method("NLST");
request.set_UsePassive(false);
request.set_UseBinary(true);
request.set_KeepAlive(false);
response = request.GetResponse();
responseStream = response.GetResponseStream();
reader = new System.IO.StreamReader(responseStream);
while (!reader.get_EndOfStream())
{
text = reader.ReadLine();
ftpFileList.addEnd(text);
//info (text);
}
reader.Close();
responseStream.Close();
response.Close();
}
Regards,
K.
Arunsubramaniam
ftpFileList element not initialised.
ReplyDelete