Slow failure reading non-existing file using SCP

Apr 14, 2014 at 8:45 AM
Hi,

I'm using ScpClient to download files. When the file exists it is fast (~10ms), but if the file does not exist the download takes about 3.5 seconds to fail. Is this normal?

I have not as yet isolated the problem to the client or the server, so it may not be an SSH.NET question ... but I ask in case this is known behaviour.

Thx

Rob
Apr 14, 2014 at 9:12 AM
Hi,

Just tried to reproduce it and it fails fast:
            var start = DateTime.Now;

            try
            {
                var scp = new ScpClient(res.host, int.Parse(res.port), res.user, res.password);
                scp.Connect();
                var file = new FileStream("bla", FileMode.OpenOrCreate, FileAccess.Write);
                scp.Download("bla", file);
                scp.Disconnect();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                var end = DateTime.Now;
                Console.WriteLine("Time: " + (end - start));
            }

            Console.ReadLine();
=>
scp: bla: No such file or directory
Time: 00:00:00.5669936
Sounds like a problem, not a known/wanted behaviour.
Do you have other servers to test?
Apr 14, 2014 at 10:49 PM
Hi,

Thanks for having a look. Interesting. The 'server' is a proprietary Linux device we manufacture. I need to investigate further.

The way you use the ScpClient is different to my implementation, I wonder if I'm using it wrong. Here is a code frag of my code:
            using (var stream = new MemoryStream((128 * 1024)))
            {
                var hasError = false;
                using (var scpClient = new ScpClient(XXX.IpAddress, XXX.UserName, XXX.Password))
                {
                    scpClient.ErrorOccurred += (x, y) => hasError = true;
                    scpClient.BufferSize = BufferSize;

                    scpClient.Connect();

                    if (scpClient.IsConnected && !hasError)
                    {
                        try
                        {
                            scpClient.Download(_sourcePath, stream);
                        }
                        catch (ScpException exception)
                        {
                            // logging stuff here ... do get the "file or directory not found".
                        }

                        scpClient.Disconnect();
                    }
                }

                // consume stream here as 'stream.ToArray()'
            }
Apr 14, 2014 at 11:01 PM
Sorry I did not answer your question about the server properly. It is a Linux box using SSH-2.0-dropbear_0.49

Thx

Rob
Apr 15, 2014 at 1:39 AM
Thanks,

I have confirmed that the 3 second delay is on the server end, nothing to do with SSH.NET.

Thanks for your help