This project is read-only.

Sftp uploads empty file

Jan 18, 2013 at 1:33 PM

Hello, im working with the library downloaded as a nuget package, building for framework 3.5

Most of what i have used works ok, but this simple code:

using (var file = File.OpenRead(localFile))
{
     Client.UploadFile(file, remoteFile);
}

Lets the file in the server with 0 bytes and no exception.

localFile is a pdf of 5Mb and remote file is tha same name and in my home directory of a RHEL x86_64 GNU/Linux

What can i check to wee what is the problem ?

Jan 18, 2013 at 1:57 PM

Problem solved, i had a bug that set the SftClient class BufferSize property in 0.

Thanks.

Jan 18, 2013 at 6:59 PM
Edited Jan 18, 2013 at 6:59 PM

Could you help me with this I am having the same problem.  Here is my code.

 

 

using (SftpClient client = new SftpClient("172.17.1.5", "user", "password")){




 client.Connect();

 MemoryStream temp = new MemoryStream();
 client.DownloadFile("Dir\\file.pdf, temp);


 client.UploadFile(temp, "Dir\\downloadedfile\\filenew.pdf");



 temp.Flush();
 temp.Close();


 fs.Flush();


 fs.Close();


}
Jan 18, 2013 at 7:43 PM

This is my working code, very simplied since i handle it as interfaces and firing event and other stuff:

// been Client
SftpClient Client = new SftpClient(Host, User, Password);

public override void GetFile(string localFile, string remoteFile)
{
    if (!Client.IsConnected)
        Client.Connect();

    using (var fileStream = File.OpenWrite(localFile))
    {
         Client.DownloadFile(remoteFile, fileStream);
    }
}

public override void PutFile(string localFile, string remoteFile)
{
    if (!Client.IsConnected)
        Client.Connect();

    using (var file = File.OpenRead(localFile))
    {
        Client.UploadFile(file, remoteFile);
    }
}

Coordinator
Jan 20, 2013 at 12:15 AM

Hi,

 

Do you get any exception or may be hanging code while uploading or method exits gracefully?

 

Thanks,

Oleg