Below code uses System.Net.Ftpwebrequest package in AX to integrate with FTP. This job demonstrates how to upload a file into FTP folder. Refer WebRequestMethods.Ftp Class for different actions.
static void FTPUploadFile(Args _args)
{
System.Object ftpo;
System.Net.FtpWebRequest request;
System.IO.StreamReader reader;
System.IO.Stream stream;
System.IO.StreamWriter writer;
System.Byte[] byteArray;
System.Text.Encoding encodingUTF8;
System.IO.Stream responseStream;
System.Net.NetworkCredential credential;
str fileContent = "File content";
int arrayLength;
;
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("STOR");
request.set_UsePassive(true);
request.set_UseBinary(true);
request.set_KeepAlive(false);
encodingUTF8 = System.Text.Encoding::get_UTF8();
byteArray = encodingUTF8.GetBytes(fileContent);
arrayLength = byteArray.get_Length();
stream = request.GetRequestStream();
stream.Write(byteArray, 0, arrayLength);
stream.Close();
}
Regards,
K.
Arunsubramaniam
No comments:
Post a Comment