"Session operation has timed out" error?

May 24, 2013 at 2:17 AM
Hi,

I am trying to use this library to upload a file via SFTP, and it connects fine and even puts an empty file onto the SFTP server, but then it just sits there and eventually times out with a session operation has timed out exception. The code is basically as follows:
            var uri = new Uri(remoteUri);
            if (uri.Scheme == "sftp") {
                // Upload the file using sftp over SSH
                var host = uri.Host;
                var userInfo = uri.UserInfo.Split(':');
                if (userInfo.Length > 1) {
                    var username = userInfo[0];
                    var password = userInfo[1];
                    using (var sftp = new SftpClient(host, username, password)) {
                        sftp.Connect();
                        using (var file = File.OpenRead(localFile)) {
                            sftp.UploadFile(file, uri.LocalPath);
                        }
                        sftp.Disconnect();
                    }
                } else {
                    throw new ArgumentException("Unable to parse username and password from URI");
                }
            }
Any idea what would cause this? I have debugged into a debug build of the source code (built with VS2012) and it gets stuck as soon as it attempts to send any data?
May 24, 2013 at 7:02 PM
Any suggestions on what to try here? This same code works perfectly to a windows server using WinSSHD and also to a Linux server. But it fails when connecting to the server we need to connect to (which I have no control over). The server they are using is EFT Server 6.1.0 Build 10.30.2009.48, if that makes any difference?
May 24, 2013 at 10:48 PM
Aha, finally found the issue! The core problem is the server we are connecting to is really, REALLY slow! I have no idea why it is so slow, but with the default buffer size of 16K, it times out trying to send data to the server. I changed it to a 1K buffer size and it worked just fine.

So, in reality I don't want to change the default buffer size, but what I do need to change is the timeout. What timeout is happening during uploads that would cause problems if the SFTP server is really slow? I plan to debug the code a bit and see if I can spot it. Worst case I can work out what buffer size works with this server and force that, but in reality the proper fix is to change the library so it handles this situation correctly ...
May 24, 2013 at 11:00 PM
Hmm, the connection we are using to this server appear to be a T1, as it runs about 130KB per second. So it makes no sense that a 16K buffer transfer would cause a timeout? I think I will try different buffer sizes, but perhaps this particular server has issues with 16K buffers?
May 24, 2013 at 11:18 PM
Pretty sure at this point there is something totally screwy with EFT Server 6.1.0. Using FireFTP to upload files to their server takes about 1:20 to upload 6MB of data. When I change the buffer size in SSH.NET to 8K, it uploaded the exact same file in 6.5 seconds! I downloaded it again and verified it was correct so clearly something is off in their SSH server causing these issues. So I am not sure there is anything we need to fix here. I have asked them to upgrade to the latest 6.5.x release to see if that resolves the issues we are seeing as well. But for now I will stick to an 8KB buffer.