This project is read-only.

Downloadind file over SFTP is slow

Jun 14, 2015 at 5:44 PM
Edited Jun 14, 2015 at 5:48 PM
I am using the following code to download file with secure FTP and the performance is 4-5 times
slower than WinSCP.
        var    client_ = new SftpClient(
                settings_.ServerAddress, 
                settings_.Username, 
                settings_.Password);
            client_.BufferSize = 8 * 1024;
            client_.Connect();
            using (FileStream file = File.Create(path))
            using (SftpFileStream sftpFileStream = 
            client_.OpenRead(String.Format("{0}\{1}",
                            settings_.RemoteFolder,settings_.RemoteFileName)))
            {
                int BUFFER_SIZE = 1024 * 4;
                byte[] buffer = new byte[BUFFER_SIZE];
                int readBytes = sftpFileStream.Read(buffer, 0, BUFFER_SIZE);
                double totalTransferedBytes = (double)readBytes;
                while (readBytes > 0)
                {
                    file.Write(buffer, 0, readBytes);
                    readBytes = sftpFileStream.Read(buffer, 0, BUFFER_SIZE);

                }
            }