web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

FTPWebRequest in Batch

(0) ShareShare
ReportReport
Posted on by 85

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();
            }
        }
    }

*This post is locked for comments

I have the same question (0)
  • Dick Wenning Profile Picture
    8,705 Moderator on at

    in case you run in batch, the code run server side with the credenails of the AOS service account.

    has the service account access right to the FTP?

    an othter check is running the ax client on the AOS, does it still work.

  • Roderik Latruwe Profile Picture
    85 on at

    Thank you for the reply Dick Wenning.

    The thing is our IP-addresses for external connection all have access to the FTP (external).

    The credentials do not depend on the AOS server, they are hard coded according to what we received from the FTP host. The AX-client still works on the AOS.

    After some more investigation here is what i could figure out:

    I could manually run the batch class on my client, but my colleague could not. He got the timeout too.

    BUT when he went to the FTP location in windows and logged on 1 time, he could run the batch client too without timeout. It seems like windows is saving this "connection" or something.

    A similar problem I've ran into with the document handling inside AX. We use sharepoint and move documents from the Axapta document handling filepath to the sharepoint location (networklocation) + change the links inside AX documenthandling. When trying to open a document in Axapta you get an error that the path doens't exist. BUT when you go to the networklocation manually in windows (\\sharepointlocation\documents\) and login once then you can open the documents in AX without errors that the path doesn't exist.

    Now these problems look very similar but are very different too. I know for one that windows might add the FTP to trusted connections. But does it really matter? It should be possible getting data from any FTP from within axapta...

    I'm testing more into this...

  • Community Member Profile Picture
    on at

    Hi Roderik,

    did you ever got to the bottom this, I'm experiencing the same issue.

    Cheers

    Soren

  • Suggested answer
    Evan Adamson Profile Picture
    105 on at

    In your line request.set_UsePassive(false); are you passing false intentionally. This means you're listening for a response from the remote server. If that is correct then maybe the remote server is the issue. If you want to initiate the connection you should pass true. I wrote a similar API and which works this way. msdn.microsoft.com/.../system.net.ftpwebrequest.usepassive(v=vs.110).aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans