FTP file transfer to another server in ax 2009
static void uploadTestFile(Args _args)
{
System.Object ftpo;
System.Object ftpResponse;
System.Net.FtpWebRequest request;
System.IO.StreamReader reader;
System.IO.Stream requestStream;
System.Byte[] bytes;
System.Net.NetworkCredential credential;
System.String xmlContent;
System.Text.Encoding utf8;
System.Net.FtpWebResponse response;
;
// Read file
reader = new System.IO.StreamReader("E:\\signed file path\Test.xml");
utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes( reader.ReadToEnd() );
reader.Close();
// little workaround to get around the casting in .NET
ftpo = System.Net.WebRequest::Create("ftp:/198.168.64.108:24/Imges/Test.xml");
request = ftpo;
credential = new System.Net.NetworkCredential("ananymous","P@ssw0rd");
request.set_Credentials(credential);
request.set_ContentLength(bytes.get_Length());
request.set_Method("STOR");
// "Bypass" a HTTP Proxy (FTP transfer through a proxy causes an exception)
// request.set_Proxy( System.Net.GlobalProxySelection::GetEmptyWebProxy() );
requestStream = request.GetRequestStream();
requestStream.Write(bytes,0,bytes.get_Length());
requestStream.Close();
ftpResponse = request.GetResponse();
response = ftpResponse;
info(response.get_StatusDescription());
}