【发布时间】:2021-09-17 02:36:52
【问题描述】:
我在 azure 门户上创建了 Sftp Container Instance。它有IP地址、主机、用户名和密码。
在创建容器实例时,我被要求创建新的存储帐户。所以,我继续进行。然后我下载了 FileZilla 客户端并使用Sftp Container Instance 的凭据连接到 sftp。
成功连接后,我从 FileZilla 上传了一个文件。
然后,我可以在使用Sftp Container Instance 创建的存储帐户的FileShare 中看到上传的文件。
我正在尝试通过 C# 代码将文件上传到 Sftp。
我先把文件上传到Azure Storage Account Containers
然后,我想将文件上传到 Sftp FileShare。
我做了以下代码:
if (path != null && fileContents != null)
{
CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(path);
cloudBlockBlob.Properties.ContentType = fileMimeType;
await cloudBlockBlob.UploadFromByteArrayAsync(fileContents, 0, fileContents.Length);
using (SftpClient client = new SftpClient("20.74.18.95", 22, "sftp", "abcd@123"))
{
using (var blobReadStream = await cloudBlockBlob.OpenReadAsync())
{
var remoteFilePath = Path.Combine("/sftpfileshare/");
client.Connect();
client.BufferSize = 4 * 1024;
client.UploadFile(blobReadStream,remoteFilePath, false);
}
}
return cloudBlockBlob.Uri.AbsoluteUri;
}
但它给我抛出了异常Failure。
我无法弄清楚我做错了什么。
请帮帮我
完整的堆栈跟踪如下:
{"Failure"}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233088
HelpLink: null
InnerException: null
Message: "Failure"
SerializationRemoteStackTraceString: null
SerializationStackTraceString: " at Renci.SshNet.Sftp.SftpSession.RequestOpen(String path, Flags flags, Boolean nullOnError)\r\n at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback)\r\n at Renci.SshNet.SftpClient.UploadFile(Stream input, String path, Boolean canOverride, Action`1 uploadCallback)\r\n at CoreConnect.Interfaces.CrossCutting.BlobStorage.BlobStorageService.UploadFileToBlobAsync(Byte[] fileContents, String fileMimeType, String fileName, ILogger logger) in D:\\Sprint7\\CoreConnect\\CoreConnect\\AzureFunctions\\CoreConnect.AzureFunctions\\CoreConnect.AzureFunctions.CrossCutting\\BlobStorage\\BlobStorageService.cs:line 91"
SerializationWatsonBuckets: null
Source: "Renci.SshNet"
StackTrace: " at Renci.SshNet.Sftp.SftpSession.RequestOpen(String path, Flags flags, Boolean nullOnError)\r\n at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback)\r\n at Renci.SshNet.SftpClient.UploadFile(Stream input, String path, Boolean canOverride, Action`1 uploadCallback)\r\n at CoreConnect.Interfaces.CrossCutting.BlobStorage.BlobStorageService.<UploadFileToBlobAsync>d__3.MoveNext() in D:\\Sprint7\\CoreConnect\\CoreConnect\\AzureFunctions\\CoreConnect.AzureFunctions\\CoreConnect.AzureFunctions.CrossCutting\\BlobStorage\\BlobStorageService.cs:line 91"
TargetSite: {Byte[] RequestOpen(System.String, Renci.SshNet.Sftp.Flags, Boolean)}
_HResult: -2146233088
_data: {System.Collections.ListDictionaryInternal}
_dynamicMethods: null
_exceptionMethod: null
_helpURL: null
_innerException: null
_ipForWatsonBuckets: 0x00007ffb2466766f
_message: "Failure"
_remoteStackTraceString: null
_source: null
_stackTrace: {sbyte[192]}
_stackTraceString: null
_watsonBuckets: null
_xcode: -532462766
_xptrs: 0x0000000000000000
【问题讨论】:
-
"t throws me the exception" 它在哪里被抛出?您能否在问题中包含完整的错误和堆栈跟踪?
-
你能不能先下载流到localfile,然后
client.UploadFile(localfile,? -
@phuzi 我已经编辑了问题并添加了堆栈跟踪。
-
@LeiYang 当我尝试在本地进行时,它会显示
permission denied -
@MartinPrikryl 谢谢 .. 它解决了我的问题