Azure functions 使用Azure函数将文件从Azure存储上载到SFTP
我试图在Azure函数中使用Renci.SshNet将文件上载到SFTP(在底部查找)。 执行此行时,我收到一个错误: client.Connect(); 错误是: 由于连接方在一段时间后没有正确响应,连接尝试失败;或者由于连接的主机未能响应,建立的连接失败。 我的用户/密码/ip/端口正确(我已通过Filezilla进行了检查) 你知道会发生什么吗? 多谢各位Azure functions 使用Azure函数将文件从Azure存储上载到SFTP,azure-functions,Azure Functions,我试图在Azure函数中使用Renci.SshNet将文件上载到SFTP(在底部查找)。 执行此行时,我收到一个错误: client.Connect(); 错误是: 由于连接方在一段时间后没有正确响应,连接尝试失败;或者由于连接的主机未能响应,建立的连接失败。 我的用户/密码/ip/端口正确(我已通过Filezilla进行了检查) 你知道会发生什么吗? 多谢各位 private static async Task<string> UploadFileToSFTP(Uri uri, s
private static async Task<string> UploadFileToSFTP(Uri uri, string sourceFileName, ILogger log )
{
string storageAccountContainer = "csvfiles4magento";
string storageConnectionString = BLOBStorageConnectionString;
string sourceFileAbsolutePath = uri.ToString();
//SFTP Parameters (read it from configurations or Azure KeyVault)
string sftpAddress = "address";
string sftpPort = "port";
string sftpUsername = "username";
string sftpPassword = "password";
string sftpPath = "var";
string targetFileName = sourceFileName;
var memoryStream = new MemoryStream();
CloudStorageAccount storageAccount;
if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))
{
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer =
cloudBlobClient.GetContainerReference(storageAccountContainer);
CloudBlockBlob cloudBlockBlobToTransfer =
cloudBlobContainer.GetBlockBlobReference(new CloudBlockBlob(uri).Name);
await cloudBlockBlobToTransfer.DownloadToStreamAsync(memoryStream);
}
var methods = new List<AuthenticationMethod>();
methods.Add(new PasswordAuthenticationMethod(sftpUsername, sftpPassword));
//Connects to the SFTP Server and uploads the file
Renci.SshNet.ConnectionInfo con = new Renci.SshNet.ConnectionInfo(sftpAddress, sftpPort, new PasswordAuthenticationMethod(sftpUsername, sftpPassword));
using (var client = new SftpClient(con))
{
client.Connect();
client.UploadFile(memoryStream, $"/{sftpPath}/{targetFileName}");
client.Disconnect();
return targetFileName;
}
}
private static async Task UploadFileToSFTP(Uri Uri、字符串sourceFileName、ILogger日志)
{
字符串storageAccountContainer=“csvfiles4magento”;
string-storageConnectionString=BLOBStorageConnectionString;
字符串sourceFileAbsolutePath=uri.ToString();
//SFTP参数(从配置或Azure KeyVault读取)
字符串sftpAddress=“地址”;
字符串sftpPort=“端口”;
字符串sftpUsername=“用户名”;
字符串sftpassword=“密码”;
字符串sftpath=“var”;
字符串targetFileName=sourceFileName;
var memoryStream=新的memoryStream();
CloudStorageAccount-storageAccount;
if(CloudStorageAccount.TryParse(storageConnectionString,out-storageAccount))
{
CloudBlobClient CloudBlobClient=storageAccount.CreateCloudBlobClient();
CloudBlobContainer CloudBlobContainer=
cloudBlobClient.GetContainerReference(storageAccountContainer);
CloudBlockBlob cloudBlockBlobToTransfer=
cloudBlobContainer.getBlockBlobreReference(新CloudBlockBlob(uri.Name);
等待cloudBlockBlobToTransfer.DownloadToStreamAsync(memoryStream);
}
var方法=新列表();
添加(新密码验证方法(sftpUsername,sftpPassword));
//连接到SFTP服务器并上载文件
Renci.SshNet.ConnectionInfo con=新Renci.SshNet.ConnectionInfo(sftpAddress、sftpPort、新密码验证方法(sftpUsername、sftpassword));
使用(var客户端=新SftpClient(con))
{
client.Connect();
client.UploadFile(memoryStream,$“/{sftpath}/{targetFileName}”);
client.Disconnect();
返回targetFileName;
}
}
请提供错误消息好吗?错误是:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机没有响应。您是否配置了sftp服务器防火墙?另外,你能告诉我你是否可以在本地运行代码吗?Sftp服务器防火墙:它是第三方托管。通过地址、用户名和密码连接到sftp,可以在我的机器上使用filezilla。我不知道如何在htrptrigger调试onpremise(可能正在使用postman?)中将流作为参数传递。是的,您可以使用postman。请提供错误消息好吗?错误是:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机无法响应,建立的连接失败。是否配置了sftp服务器防火墙?另外,你能告诉我你是否可以在本地运行代码吗?Sftp服务器防火墙:它是第三方托管。通过地址、用户名和密码连接到sftp,可以在我的机器上使用filezilla。我不知道如何在htrptrigger内部调试中将流作为参数传递(可能正在使用postman?)是的,您可以使用postman。