0
votes

I'm working with Azure Functions 2.0 and I need to fetch documents from CosmosDB, format them into a single CSV file and upload it to an SFTP location.

I'm able to query and fetch documents via the CosmosDB input binding and will be probably use the CSVHelper library to handle CSV formatting. But I can't seem to find an SFTP output binding. I've checked:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#supported-bindings

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob?tabs=csharp#output

Apparently, there used to be an External File trigger/binding which has been deprecated (Corrupt file when using Azure Functions External File binding)

What is the best way to stream upload a file to an SFTP location from an Azure Function?

1

1 Answers

1
votes

According to my research, at the moment, Azure function does not provide the SFTP binging. So if you want to upload file to SFTP server, you need to implement ii with you code. Regarding how to implement it, you can use Renci.SshNet.Async. For example

            string host = ""; // your server name
            int port =22 ;// your port
            string username ="";// your sftp server username
            string password="";// your sftp server  password
            SftpClient client = new SftpClient(host, port, username, password);
            client.Connect();
            string path = "";// The file to write to
            byte[] bytes = Encoding.UTF8.GetBytes("test");
            client.WriteAllBytes(path, bytes);
            client.Dispose();
            client.Disconnect();