I created Sftp Container Instance
on azure portal. It has IP address, Host, username and password.
While creating the container instance, I was asked to create new storage account. So, I proceeded with it. Then I downloaded FileZilla Client and connect with sftp using the credentials of that Sftp Container Instance
.
After Successful Connection, I uploaded a file from FileZilla.
Then, I could see that uploaded file in the FileShare
of storage account that was created with Sftp Container Instance
.
I am trying to upload the file to Sftp through C# code.
I first uploaded the file to Azure Storage Account Containers
and then, I want to upload the file to Sftp FileShare.
I did the following code :
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;
}
But it throws me the exception Failure
.
I am unable to figure out what I am doing wrong.
Please help me
Complete Stack Trace is below :
{"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