-1

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

Simran Kaur
  • 217
  • 1
  • 5
  • 15

1 Answers1

-1

Blobs / Shares are different concepts under Azure Storage Account. What you actually need is to upload the file to Azure File Shares:

https://learn.microsoft.com/en-us/dotnet/api/overview/azure/storage.files.shares-readme

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • Isn't there any way to upload the file using sftp credentials and it gets uploaded to its File Share ? @Thiago Custodio – Simran Kaur Jul 07 '21 at 06:47