Hello,
I made a batch class to check an FTP for files, download them and delete them on the FTP.
When I run it manually (not in batch) it works perfectly and downloads all files in the FTP and deletes them when the downloading is done.
The problem starts when i try to run this in batch, I tried both serverside and client batches.
Both of them give a timout error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.WebException: The operation has timed out.
at System.Net.FtpWebRequest.CheckError()
at System.Net.FtpWebRequest.GetResponse()
--- End of inner exception stack trace ---
Does anyone have any experience downloading files from an FTP in batch?
I have tried setting the timeout time higher. I also tested the connection on the servers executing the batch-job and i can access the FTP. So it's not a firewall issue. I think it must be something within AX but I can't really think of anything.
this is the code (note: downloadfile and deletefile is the same code to make the connection with a differenct set_method():
permissionSet = new Set(Types::Class);
files = new List(types::String);
permissionset.add(new InteropPermission(InteropKind::DllInterop));
permissionset.add(new InteropPermission(InteropKind::ClrInterop));
CodeAccessPermission::assertMultiple(permissionset);
ftpo = System.Net.WebRequest::Create(<ftp link>);
request = ftpo;
request.set_KeepAlive(false);
request.set_UsePassive(false);
request.set_UseBinary(true);
request.set_Method("NLST");
credential = new System.Net.NetworkCredential(<user>,<pw>);
request.set_Credentials(credential);
try
{
//first get the filelist from FTP
response = request.GetResponse();
reader = new System.IO.StreamReader(response.GetResponseStream());
while(!reader.get_EndOfStream())
{
text = reader.ReadLine();
files.addStart(text);
}
reader.Close();
response.Close();
CodeAccessPermission::revertAssert();
if(files.elements() >0)
{
it = New ListIterator(files);
while(it.more())
{
filename = it.value();
downloadfile(filename);
deleteFile(filename);
it.next();
}
}
}