This project is read-only.

ScpClient.Upload Hanging

Mar 5, 2012 at 5:23 PM


I've been using SSH.Net and SshClient to talk to a linux machine (dropbear) and everything works perfectly.

However, I cannot seem to get ScpClient to work. The upload function just exceptions thrown.

I've seen the other thread about problems with dropbear and have tried the suggested workarounds with no luck.

Does anyone see a problem with my code?

file is in the format "C:\folder\filename"
dest is in the format "/folder/subfolder/filename"


public static void SendSCPFile(string ip, string file, string dest)
    ScpClient scp = new ScpClient(ip, "root", password);

    //FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);

        scp.BufferSize = 8 * 1024;

        //scp.Upload(fs, dest);
        scp.Upload(new FileInfo(file).OpenRead(), dest);

    catch (Exception ex)
        ReportError("Connection failed!");

        throw ex;

Mar 5, 2012 at 11:30 PM


its weird as it suppose to either time out or throw an exception.


When it hangs, can you press pause and see what line it hangs in?

Also, what server you connecting too and does it occurs if you using different servers?



Mar 8, 2012 at 5:35 PM

I am experiencing the exact same problem.  The code hangs in the Read(byte[], int, int) method of the PipeStream class, PipeStream.cs lines 180, 181:

while (!this.ReadAvailable(count))
Mar 9, 2012 at 3:34 PM

Thanks for info,

It looks like its waiting to read more data from the server which is not coming.

Does this problem occurs if you use different server?

Also, does it occurs only with specific file?



Apr 30, 2012 at 8:14 PM

Sorry for they delay! I haven't been able to make time for this project in a while...

I was able to confirm that my code hangs in the exact same place as GreenLeaf's. I dug a little deeper to discover that the scp server I'm using does not like the -q argument for some reason. So, I edited your code to see how it works without the -q. Now Upload is throwing a "scp: error: unexpected filename: <filename>" error. This happens with any file I give it.





Apr 30, 2012 at 9:30 PM
Edited Apr 30, 2012 at 9:30 PM

So I tried the workaround posted in this thread ( and this cleared up the unexpected filename exception. Now I'm seeing another problem :-)


Sending a text file seems to work fine. However, when I send a larger binary file I receive a SocketException ("An existing connection was forcibly closed by the remote host"). When I step through the code however, the send is successful. The exception is thrown by line 118 in Session.NET.cs:


sent += this._socket.Send(data, sent, length - sent, SocketFlags.None);
May 1, 2012 at 3:35 PM

I guess when it comes to binary file, it has some information that server doesnt know what to do with it and closes the connection as it could potentially security breach.


Can you log this as an issue, as I dont have much time now to look into this and I will get back to it as soon as I have time,

Also, can you attach this file, if possible, since it seems to me thats what causing problems.