This project is read-only.

Mike

Feb 28, 2011 at 6:19 AM

Hi,

Can you give a sample code for upload and download files. When I upload a file, the file is created, but the content is empty. I don't know why. Here is my code:

string path = "file.txt";

 FileStream fs = File.Create(path);

//add some string to file.txt

  Renci.SshClient.SftpClient sftpClient = new SftpClient("hostname","username", "password");
  sftpClient.Connect();
  sftpClient.UploadFile(fs,"path/filename");
  fs.Close();

 

 

 

Coordinator
Feb 28, 2011 at 1:47 PM

Hi,

 

Sorry I dont have more examples in help file.

 

You can refer to test cases that I have in a source code but here is one example:

            using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
            {
                sftp.Connect();

                string uploadedFileName = Path.GetTempFileName();
                string remoteFileName = "you file path goes here";

                this.CreateTestFile(uploadedFileName, 1);
                var exceptionOccured = false;

                try
                {
                    using (var file = File.OpenRead(uploadedFileName))
                    {
                        sftp.UploadFile(file, remoteFileName);
                    }
                }
                catch (SshPermissionDeniedException)
                {
                    exceptionOccured = true;
                }

                sftp.Disconnect();

                Assert.IsTrue(exceptionOccured);
            }

Thanks,

Oleg

Feb 28, 2011 at 3:57 PM

Oleg,

Thank you very much! The problem is solved now!

Aug 2, 2012 at 11:21 AM
Edited Aug 3, 2012 at 8:05 AM

Thanks, problem solved too.