ScpClient.Upload Hanging

Mar 5, 2012 at 4:23 PM

Hi,

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 hangs...no 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"

Thanks!
-Dan


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);

    try
    {
        scp.BufferSize = 8 * 1024;
        scp.Connect();

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

        scp.Disconnect();
    }
    catch (Exception ex)
    {
        ReportError("Connection failed!");

        throw ex;
    } 
}
 

Coordinator
Mar 5, 2012 at 10:30 PM

Hmm,

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?

Thanks,

Oleg

Mar 8, 2012 at 4: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))
  Monitor.Wait(this._buffer);
Coordinator
Mar 9, 2012 at 2: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?

Thanks,

Oleg

Apr 30, 2012 at 7: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.

 

Thanks!

-Dan

 

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

So I tried the workaround posted in this thread (http://sshnet.codeplex.com/discussions/284021) 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);
Coordinator
May 1, 2012 at 2: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.

Thanks,

Oleg