SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

SftpClient upload file doesn't work in UWP and Console applications.

Open don-pironet-hatch opened this issue 8 months ago • 2 comments

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.");
                    });
             }

don-pironet-hatch avatar May 31 '24 11:05 don-pironet-hatch