开发者

SFTP SSH2 Download Rate (C#)

开发者 https://www.devze.com 2023-03-19 04:29 出处:网络
I am developing a C# Console Applic开发者_高级运维ation which downloads files from an SFTP Server with SSH Key Pair Authentication.

I am developing a C# Console Applic开发者_高级运维ation which downloads files from an SFTP Server with SSH Key Pair Authentication.

I am using the Chilkat API.

The files I am attempting to download are very large, between 8GB-13GB.

Currently the max download speed I can get using my app is around 570 KB/s

If I try to download the same file using FileZilla I get downloads speeds of 2.6 MB/s

Running from the same computer on the same network.

Is there anyway to match the download speeds of FileZilla with a console app?


You probably need a larger TCP maximum window size: http://msdn.microsoft.com/en-us/library/ms819736.aspx

The .NET function to control it is Socket.SetSocketOption(SocketOptionName.ReceiveBuffer)


I know this is super old but no one has explicitly answered it yet. Chilkat recommends increasing the SoRcvBuf and SoSndBuf sizes if you are having network performance. I was having the exact same issues as you and this fixed my problem.

From ChilKat documentation:

public int SoSndBuf {get; set; }

Sets the send buffer size socket option. Normally, this property should be left unchanged. The default value is 0, which indicates that the send buffer size socket option should not be explicitly set (i.e. the system default value, which may vary from system to system, should be used).

This property can be changed if upload performance seems slow. It is recommended to be a multiple of 4096. To see the current system's default send buffer size, examine the LastErrorText property after calling any method that establishes a connection. It should be reported under the heading "SO_SNDBUF". To boost performance, try setting it equal to 2, 3, or 4 times the default value.


I had this problem before when I set the byffer size too small.

For realistic results, buffer size should vary according to filesize. You don't want small buffers for big files (your case, where bottleneck is your app managing the buffer, not the connection speed).

You also don't want big buffers for smaller files, so that you won't follow the progress.


There are several factors that influence SFTP speed. SSH buffer size, SFTP buffer size, pipeline length are among those factors (encryption algorithm is another one). One more factor is a language. Optimized C++ code will always be faster than C# code. So while you can achieve comparable speeds with FileZilla, you are unlikely to match them.

Also did you check alternative SFTP components (there are plenty of them on the market)?


SFTP is secure, that's why it's downloading at a slower rate. If you want similar speeds, you should download using FTP or attempt to modify the server settings to allow for non-limiting speeds.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号