EndUploadFile gives Error: Renci.SshNet.Common.SftpPathNotFoundException: File not found

Feb 8, 2012 at 11:08 PM

Hey everyone.  When I run the code below, I get the error.  Any ideas?  Can someone point me to sample code? Thanks in advance.

                    string filePathTFN = "C:\\test1.txt";
                    var mem1 = File.OpenRead(filePathTFN);
                    var asynch1 = sftp.BeginUploadFile(mem1, "/Call4HealthtoMediMedia/" + filePathTFN, null, null);

                    while (!asynch1.IsCompleted)
                    {
                        Console.WriteLine("Uploading " + filePathTFN);
                        Thread.Sleep(100);
                    }

                    sftp.EndUploadFile(asynch1);    

                    sftp.Disconnect();

////////////////////////////////////////////////////

Error: Renci.SshNet.Common.SftpPathNotFoundException: File not found

   at Renci.SshNet.Common.AsyncResult.EndInvoke() in C:\Dev\Visual Studio 2010\Projects\Renci.SshNet\Common\AsyncResult.cs:line 93

   at Renci.SshNet.SftpClient.EndUploadFile(IAsyncResult asyncResult) in C:\Dev\Visual Studio 2010\Projects\Renci.SshNet\SftpClient.cs:line 603

 

 

Coordinator
Feb 10, 2012 at 2:45 AM

Hi,

 

Here the sample code that I used to test it:

            using (var sftpClient = new SftpClient(connectionInfo))
            {
                sftpClient.Connect();
                EventWaitHandle wait = new AutoResetEvent(false);
                Console.WriteLine("\nUpload started.");
                var asynch = sftpClient.BeginUploadFile(File.OpenRead(@"C:\Test\small.txt"), "/home/oleg/test1.txt",
                    delegate(IAsyncResult ar)
                    {
                        Console.Write("\nCallback called.");
                        wait.Set();
                    },
                    null);

                var sftpASynch = asynch as SftpAsyncResult;
                while (!sftpASynch.IsCompleted)
                {
                    Console.Write(string.Format("\rUploaded {0} bytes ", sftpASynch.UploadedBytes));
                    Thread.Sleep(100);
                }
                Console.Write(string.Format("\rUploaded {0} bytes ", sftpASynch.UploadedBytes));
                sftpClient.EndUploadFile(asynch);
                wait.WaitOne();
            }

I copied as I have it in my test utility but didn't run it so hopefully it still works.

For more examples you can download source code from the "Source Code" tab and you can find Tests project there which have an examples.

 

Hope it helps,

 

Thanks,

Oleg