SFTP(SSH File Transfer Protocol)传输速度慢可能由多种因素导致。以下是一些常见的优化方案:
检查网络带宽和延迟
ping
和traceroute
检查网络延迟和路径speedtest-cli
测试实际可用带宽调整TCP窗口大小
# 临时调整(需root权限)
sysctl -w net.ipv4.tcp_window_scaling=1
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
尝试不同的加密算法
aes128-ctr
而非aes256-cbc
/etc/ssh/sshd_config
和~/.ssh/config
:
Ciphers aes128-ctr,aes192-ctr,aes256-ctr
调整SSH配置
# 在/etc/ssh/sshd_config中添加
UseDNS no
GSSAPIAuthentication no
增加并发连接数
lftp
支持多线程传输:
bash
lftp -u user,pass sftp://server -e "mirror --parallel=4 /remote/path /local/path"
检查服务器负载
top
或htop
检查CPU和内存使用情况iotop
或iostat
使用更高效的SFTP客户端
lftp
、rsync
或支持多线程的客户端调整缓冲区大小
# 使用sftp时指定更大的缓冲区
sftp -B 65536 user@host
压缩传输(适合文本文件)
sftp -C user@host
考虑使用其他协议
分段传输大文件
# 分割文件
split -b 500M largefile largefile_part
# 传输后合并
cat largefile_part* > largefile
通过以上方法综合调整,通常可以显著提升SFTP传输速度。建议先从网络和加密算法调整开始,逐步排查瓶颈所在。