Uploading a file generates a session operation has timed out error

Oct 16, 2013 at 7:25 PM
Code inserted at the end. I have a console application that when executed;
1) Queries a database server
2) Creates a file out of the result
3) Connects to a sFtp server
4) Uploads the file created

What I am seeing is that everything works fine until it tries to upload the file. A zero length file gets created on the server and then an exception is thrown. The code in class is basically stock example code so I'm uncertain as to what to check to fix this.

There was an error in the following location: Upload file to Speed Pay
The following exception was caught:
Session operation has timed out



public class SecureFTP
{

    public string FileName { get; set; }
    public string FilePath { get; set; }
    public string RemoteHost { get; set; }
    public string RemoteUserName { get; set; }
    public string RemotePassWord { get; set; }

    public bool SendFile()
    {
        try
        {
            Stream input = File.OpenRead(FilePath + FileName);
            var connectionInfo = new PasswordConnectionInfo(RemoteHost, RemoteUserName, RemotePassWord);
            SftpClient sshclient = new SftpClient(connectionInfo);
            sshclient.
            sshclient.Connect();
            sshclient.UploadFile(input, FileName);
            sshclient.Disconnect();

            return true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public string ReceiveFile()
    {
        try
        {

            string FilePath = this.FilePath, fileName = this.FileName, RemoteHost = this.RemoteHost, RemoteUserName = this.RemoteUserName;
            string RemotePassWord = this.RemotePassWord;
            Stream FileOutput = File.OpenWrite(FilePath + fileName);
            var connectionInfo = new PasswordConnectionInfo(RemoteHost, RemoteUserName, RemotePassWord);
            SftpClient test = new SftpClient(connectionInfo);
            test.Connect();
            //test.ChangeDirectory(RemoteDirPath);
            test.DownloadFile(fileName, FileOutput);
            if (File.Exists(FilePath + fileName))
            {
                test.Disconnect();
                FileOutput.Close();

                Stream fr = File.OpenRead(FilePath + fileName);
                StreamReader sr = new StreamReader(fr);
                string Contents = sr.ReadToEnd();
                return Contents;

            }
            else
            {
                throw new Exception("An error occured attempting to download the file " + fileName);
            }

        }
        catch (Exception ex_overall)
        {
            throw ex_overall;
        }
    }



}
Oct 17, 2013 at 2:46 AM
After looking through a number of discussions that had similar issues as described above I found the code that sets the buffer site used for the sFtpClient. I reduced it to 1k just to see if would make any difference. In the past I have found that although it works it would work slowly but demonstrate the issue. Viola, it wrote the file.

The weird aspect to this that I didn't see in other posts and should have mentioned before is that this works perfectly on Windows 7, or at least my Windows 7 client (Laptop). It was only when I moved it to a Windows Server 2008 R2 that I ran into the issue described in the original post.


public SftpClient(ConnectionInfo connectionInfo)
        : base(connectionInfo)
    {
        this.OperationTimeout = new TimeSpan(0, 0, 0, 0, -1);
        //this.BufferSize = 1024 * 16;
        this.BufferSize = 1024;
    }