1

I am working with Windows Azure Websites and Web Jobs.

I have a console application that I use to download an FTP file nightly. They recently switch from passive to active FTP. I do not have any control over this.

The code attached was working for passive and works for active on my computer. However, it does not work when I add it to a webjob on Azure.

In this code I am able to get the content length, so I am logging in correctly and I have the correct URL.

     Dim request As FtpWebRequest = DirectCast(FtpWebRequest.Create(strTempFTPUrl), FtpWebRequest)

        request.Method = WebRequestMethods.Ftp.GetFileSize
        Dim nc As New NetworkCredential(FTPUserName, FTPPassword)
        request.Credentials = nc
        request.UseBinary = True
        request.UsePassive = False
        request.KeepAlive = True
        request.Proxy = Nothing

        ' Get the result (size)
        Dim resp As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
        Dim contLen As Int64 = resp.ContentLength

        ' and now download the file
        request = DirectCast(FtpWebRequest.Create(strTempFTPUrl), FtpWebRequest)
        request.Method = WebRequestMethods.Ftp.DownloadFile
        request.Credentials = nc
        request.UseBinary = True
        request.UsePassive = False
        request.KeepAlive = True
        request.Proxy = Nothing

        resp = DirectCast(request.GetResponse(), FtpWebResponse)

The error that I receive is this:

The underlying connection was closed: An unexpected error occurred on a receive. This happens on the second "resp = DirectCast(request.GetResponse(), FtpWebResponse)"

Does anyone have any suggestions on what I can do?

Edit: This is not a VM so as far as I know I do not have control over the firewall. This is a standard website. Thank you very much!

user242158
  • 11
  • 2

1 Answers1

0

I was with this same problem, I was able to solve by increasing the connection limit per point. By default it comes set to 2 I increased to 10

req.ServicePoint.ConnectionLimit = 10;

If you have timeout problem, also change the properties timeout and readwritetimeout.

Below is the link for a case similar to ours.

How can I programmatically remove the 2 connection limit in WebClient

Community
  • 1
  • 1