SSH.NET
SSH.NET copied to clipboard
SftpClient upload file doesn't work in UWP and Console applications.
We are trying to upload a file in our UWP application and Console applications. Connecting seems to work fine but uploading doesn't. It always creates a 0 byte file.
The upload callback is never executed and it ends immediately even for a file of a couple of mb's.
await Task.Run(async () =>
{
string fileName = "foo.tar";
string filePath = $"/mnt/userdata/{fileName}";
var sshPassword = "test";
var stream = await file.OpenStreamForReadAsync();
var sftpClient = new SftpClient(ipAddress, "root", sshPassword);
sftpClient.Connect();
sftpClient.UploadFile(
stream,
filePath ,
uploaded =>
{
Console.WriteLine($"Uploaded {(double)uploaded / stream.Length * 100}% of the file.");
});
}