Upload file to ftps server using time trigger Azure Function returns error

Nandini Dhall 1 Reputation point
2021-07-01T07:12:35.067+00:00

Hi,

I'm trying to create a timer trigger Azure Function to upload a file to FTPS location. The below code works fine in a Console Application. However, when this is executed inside a function app, it gives the following error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I'm using FluentFTP for this. Here is the code snippet:

using (var ftp = new FtpClient("hostname", 990, "username", "password"))
{
ftp.ConnectTimeout = 87878777; // I added this just for testing purpose.
ftp.DataConnectionType = FtpDataConnectionType.EPSV;
ftp.EncryptionMode = FtpEncryptionMode.Implicit;
ftp.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
ftp.Connect();
// upload a file to an existing FTP directory
ftp.UploadFile(@"sourcefilepath", "remotefilePath");
}

I'm not able to find the root cause as to why this would fail with Azure Function and work fine otherwise. Can someone please guide?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,936 Reputation points Moderator
    2021-07-01T12:02:03.437+00:00

    anonymous user It looks more like a SocketException. Can you confirm if the issue is observed intermittently and in the full exception trace you see System.Net.Sockets.SocketException trace?
    If you are running your code in the function app consumption plan then this could observed when your application have utilized all the available sockets for the consumption plan. The suggestion would be reuse the connection object.

    If you are executing in other plans and the issue is not intermittently then verify whether your function is under VNET that would cause this issue. The issue could also observed due to your FTP server end where the connection could be established from the function to your ftp server. If the issue is not intermittently then I will suggest to verify your FTP server whether there is any configuration/firewall that is blocking the connection.

    Sharing some of the reference articles:
    https://devblogs.microsoft.com/premier-developer/reducing-snat-port-consumption-in-azure-app-services/
    https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-intermittent-outbound-connection-errors

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.