繁体   English   中英

将文件从 Azure Function 上传到 SFTP 位置

[英]Upload file to SFTP location from Azure Function

我正在使用 Azure Functions 2.0,我需要从 CosmosDB 获取文档,将它们格式化为单个 CSV 文件并将其上传到 SFTP 位置。

我能够通过 CosmosDB 输入绑定查询和获取文档,并且可能会使用 CSVHelper 库来处理 CSV 格式。 但我似乎找不到 SFTP output 绑定。 我检查过:

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

显然,曾经有一个外部文件触发器/绑定已被弃用( 使用 Azure 函数外部文件绑定时损坏的文件

ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 将文件从 Azure Function 上传到 SFTP 位置的最佳方法是什么?

根据我的研究,目前 Azure function 不提供 SFTP 绑定。 所以如果你想上传文件到 SFTP 服务器,你需要用你的代码实现 ii。 关于如何实现它,您可以使用Renci.SshNet.Async 例如

            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();

我正在 Azure 函数中从事类似的项目,并且正在使用 Rebex.Sftp 库进行文件传输。 到目前为止,它很容易使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM