sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
MIT License
3.87k stars 915 forks source link

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

Open don-pironet-hatch opened 2 weeks ago

don-pironet-hatch commented 2 weeks ago

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.");
                    });
             }
Rob-Hague commented 1 week ago

Sorry, I can see at least one thing wrong with UploadFile (it only checks for an "OK" response) but I can't see anything that would make it return immediately, assuming you are on the latest version and whatever stream is is not returning 0 immediately. Would probably require debugging into the library code.