File transfer with custom sftp connector using Azure Function

Bhattacharjee, Pratyay 121 Reputation points
2021-06-19T00:52:32.977+00:00

Hi,

We are trying to sftp files using the SftpClient class from the Renci.SshNet package in an Azure function but frequently it throws an error as - Error System.Net.Sockets.SocketException (10060): 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.
We have already whitelisted all the IP ranges for the Function App where the Azure Function is hosted for the specific region, on the destination server.
Also, sometimes the sftp connection is successful as well but most of the times the connection fails with the above error.
Can you please advise what could be the issue here.
Is it possible that the IP for the function app might go beyond the list of IP ranges provided by Microsoft for the specific region, due to which the firewall is blocking the connection in the destination server.

Thanks!

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

Accepted answer
  1. Bhattacharjee, Pratyay 121 Reputation points
    2021-06-23T22:25:00.85+00:00

    I was able to find the additional Outbound IP addresses for the function app and got them whitelisted on the destination server. After that the SFTP connectivity is working fine.

    Just for reference, I was able to locate the additional Outbound IP addresses (which were not listed in the microsoft documentation of IP ranges by regions) under Function App --> Settings --> Networking (preview) --> Outbound Traffic (Outbound addresses).

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. MayankBargali-MSFT 69,991 Reputation points
    2021-06-21T06:01:54.637+00:00

    Hi @Bhattacharjee, Pratyay

    Welcome to Microsoft Q&A! Thanks for posting the question.

    As per the error this is more towards the socket exception at the client/server or in the network in between.
    If you are running your function in consumption plan then there are limited number of sockets available for your application to communicate. If you are in webapp plan you can refer to the limit here.

    As you have mentioned that you are using the SFTP connector so there would be outbound calls that uses socket to communicate. I will suggest you to review your function code and verify that you are reusing the object/connection so the communication happens through the same socket rather than creating the new one which could cause the socket exception at the function app end.


  2. Bill Bell 101 Reputation points
    2021-06-21T12:08:19.517+00:00

    I would recommend trying WinSCP. Install app on PC and make you can sftp from desktop. Install WinSCP Nuget package in VS. Then make sure you can ftp from Azure function when you run it on your PC. When you run in Azure I had an issue with executable path. Look at https://learn.microsoft.com/en-us/answers/questions/442547/newbie-getting-winscp-working.html