Upload Issue

Feb 9, 2015 at 9:08 AM
Hi Team,

when i am trying to upload file using SSH.net i am getting below error:

Renci.SshNet.Common.SshException was unhandled
Message=Failure
Source=Renci.SshNet
StackTrace:
   at Renci.SshNet.Sftp.SftpSession.RequestOpen(String path, Flags flags, Boolean nullOnError)
   at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback)
   at Renci.SshNet.SftpClient.UploadFile(Stream input, String path, Boolean canOverride, Action`1 uploadCallback)
   at ConsoleApplication2.Program.FileUploadUsingSftp() in C:\Users\armahe\documents\visual studio 2010\projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 52
   at ConsoleApplication2.Program.Main(String[] args) in C:\Users\armahe\documents\visual studio 2010\projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 15
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException:

i have one file at my local system at location "D:/Test/test.xml.PGP" and want to upload this file to SFTP at location
@SFTP_HOST/SFTP_TestFolder/(here i want to place 'test.xml.PGP' file). For this i have written this piece of code.

var RenciSFTP = new Renci.SshNet.SftpClient(sftpHost, username, password);
string filePath = @"D:/Test/test.xml.PGP";
using (Stream fileStream = File.OpenRead(filePath))
            {                    
                RenciSFTP.ConnectionInfo.Timeout = new TimeSpan(0, 5,00);
                Console.WriteLine("Connecting...{0},{1},{2}", sftpHost, username, password);
                RenciSFTP.Connect();
                Console.WriteLine("connected,  uploading file from location :", fileName);

                var remotePath = "./" + fileName;

                RenciSFTP.UploadFile(fileStream, "/SFTP_TestFolder",true);
                RenciSFTP.Disconnect();
            }