BenjaminSoulier avatar image
0 Votes"
BenjaminSoulier asked BenjaminSoulier commented

WebJob: FtpWebRequest to remote server always fail since a few weeks

Hello there

I have some code implemented into my app logic pulling some CSV files from a partner FTP server.

This code has been working for a while, but it just stopped working over the past few weeks.

The code is fairly simple and just connect to an FTP endpoint to download a file:

         var path = ConfigurationManager.AppSettings["ftpFilePath"];
         var request = (FtpWebRequest)WebRequest.Create(path);
         request.Method = WebRequestMethods.Ftp.DownloadFile;

         var response = (FtpWebResponse)request.GetResponse();
         var responseStream = response.GetResponseStream();
         var reader = new StreamReader(responseStream);
         var fileContent = reader.ReadToEnd();

This just topped working, giving this error:
Unhandled Exception: System.Net.WebException: Unable to connect to the remote server

I also tried another lib (FluentFTP) to see how that would work, and kind of a similar error came up:
Unhandled Exception: System.TimeoutException: Timed out trying to connect!

Both piece of code connecting to the FTP server I am using work locally without any issues.
Using my Command Line based app into WebJobs just flat-out fails with the errors posted above.

This indicates a change in how connections are done to the outside from within an App Service, is there anything done recently that could make this happen?

Any ideas?

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for reaching here! Could you please confirm if you are using Azure Web job ? and your code runs fine in local machine however in Azure it throws error? Let us know to help you better on this.

0 Votes 0 ·

Hey there!

My code run as part of Azure Web Jobs and the FTP client does not work.
Running the exact same code works like a charm locally, this is exactly the behavior I am getting.

Cheers, Ben

0 Votes 0 ·

Could you please check if there is Kudu Network restriction.

Webjob runs in its sandbox, the only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports.
As its mentioned here that: Applications can create a socket which can listen for connections from within the sandbox. For example, two processes within the same app may communicate with one another via TCP sockets; connection attempts incoming from outside the sandbox, albeit they be on the same machine, will fail.

Also, Check article: SFTP/FTPS file transfers in Microsoft Azure WebJob might be helpful.

Let us know.

0 Votes 0 ·
Show more comments

0 Answers