Eyt*_*tan 8 linux ssh scp windows shell-script
我使用以下 scp 语法将大量文件从 Linux red-hat 5 传输到 Windows 计算机(在 Temp 目录下)。
Windows 机器上已经安装了 SSH 服务器。我在 shell 脚本中使用这一行:
sshpass -p '$password' /usr/bin/scp -o StrictHostKeyChecking=no $FILE USER_1@14.187.12.139:'D:/Temp'
Run Code Online (Sandbox Code Playgroud)
大多数情况下文件传输成功,但有时scp
在文件传输过程中似乎会卡住?连接显示正常,如 ping 等。
我收到以下错误scp
(很长一段时间后):
ssh_exchange_identification: read: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)
scp
不稳定并且卡住,这个问题有什么解决办法吗?scp
?(考虑到我需要100%的稳定性)我不会那么怀疑scp
。如果它有时能正常工作,这听起来更像是您的以下设备的硬件问题:
我会先执行一些基准测试来消除这些项目。您可以查看以下针对初学者的 U&L 问答:
\n\n\n\nscp
&ssh
您可以-v
向这两个命令添加开关以获得更详细的输出。例如:
# generate sample data\n$ dd if=/dev/zero of=10MB.testfile bs=1k count=10k\n10240+0 records in\n10240+0 records out\n10485760 bytes (10 MB) copied, 0.0422862 s, 248 MB/s\n\n$ ls -l 10MB.testfile \n-rw-rw---- 1 saml saml 10485760 Jul 29 17:09 10MB.testfile\n\n# test copy 10MB file\n$ scp -v 10MB.testfile remoteserver:~\nExecuting: program /usr/bin/ssh host removeserver, user (unspecified), command scp -v -t -- ~\nOpenSSH_5.5p1, OpenSSL 1.0.0e-fips 6 Sep 2011\ndebug1: Reading configuration data /home/saml/.ssh/config\ndebug1: Applying options for *\ndebug1: Applying options for removeserver\ndebug1: Applying options for *\ndebug1: Reading configuration data /etc/ssh/ssh_config\ndebug1: Applying options for *\ndebug1: auto-mux: Trying existing master\nControl socket connect(/home/saml/.ssh/master-sam@192.168.1.200:22): Connection refused\ndebug1: Connecting to 192.168.1.200 [192.168.1.200] port 22.\ndebug1: Connection established.\ndebug1: identity file /home/saml/.ssh/id_dsa type 2\ndebug1: identity file /home/saml/.ssh/id_dsa-cert type -1\ndebug1: identity file /home/saml/.ssh/qm-dev-servers type 1\ndebug1: identity file /home/saml/.ssh/qm-dev-servers-cert type -1\ndebug1: Remote protocol version 2.0, remote software version OpenSSH_4.3\ndebug1: match: OpenSSH_4.3 pat OpenSSH_4*\ndebug1: Enabling compatibility mode for protocol 2.0\ndebug1: Local version string SSH-2.0-OpenSSH_5.5\ndebug1: SSH2_MSG_KEXINIT sent\ndebug1: SSH2_MSG_KEXINIT received\ndebug1: kex: server->client aes128-ctr hmac-md5 none\ndebug1: kex: client->server aes128-ctr hmac-md5 none\ndebug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent\ndebug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP\ndebug1: SSH2_MSG_KEX_DH_GEX_INIT sent\ndebug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY\ndebug1: Host \'192.168.1.200\' is known and matches the RSA host key.\ndebug1: Found key in /home/saml/.ssh/known_hosts:30\ndebug1: ssh_rsa_verify: signature correct\ndebug1: SSH2_MSG_NEWKEYS sent\ndebug1: expecting SSH2_MSG_NEWKEYS\ndebug1: SSH2_MSG_NEWKEYS received\ndebug1: Roaming not allowed by server\ndebug1: SSH2_MSG_SERVICE_REQUEST sent\ndebug1: SSH2_MSG_SERVICE_ACCEPT received\ndebug1: Authentications that can continue: publickey,gssapi-with-mic,password\ndebug1: Next authentication method: publickey\ndebug1: Offering public key: /home/saml/.ssh/id_dsa\ndebug1: Authentications that can continue: publickey,gssapi-with-mic,password\ndebug1: Offering public key: /home/saml/.ssh/qm-dev-servers\ndebug1: Server accepts key: pkalg ssh-rsa blen 279\ndebug1: Authentication succeeded (publickey).\ndebug1: channel 0: new [client-session]\ndebug1: setting up multiplex master socket\nControlSocket /home/saml/.ssh/master-sam@192.168.1.200:22 already exists, disabling multiplexing\ndebug1: Entering interactive session.\ndebug1: Sending environment.\ndebug1: Sending env XMODIFIERS = @im=none\ndebug1: Sending env LANG = en_US.utf8\ndebug1: Sending command: scp -v -t -- ~\nSending file modes: C0660 10485760 10MB.testfile\nSink: C0660 10485760 10MB.testfile\n10MB.testfile 100% 10MB 3.3MB/s 00:03\xc2\xb7\xc2\xb7\xc2\xb7\xc2\xb7\ndebug1: client_input_channel_req: channel 0 rtype exit-status reply 0\ndebug1: channel 0: free: client-session, nchannels 1\ndebug1: fd 0 clearing O_NONBLOCK\ndebug1: fd 1 clearing O_NONBLOCK\nTransferred: sent 10499080, received 4936 bytes, in 4.0 seconds\nBytes per second: sent 2610912.6, received 1227.5\ndebug1: Exit status 0\n
Run Code Online (Sandbox Code Playgroud)\n\n您可以添加其他-v
开关以获得更详细的输出。例如:
$ scp -vvv ...\n
Run Code Online (Sandbox Code Playgroud)\n\n在对此进行更多研究时,我遇到了这个解决方法,它支持@Gilles 的观点,即这可能是防火墙问题。sshd
解决方案是使用以下命令(以管理员身份)在运行服务的 Windows 端禁用状态检查:
% netsh advfirewall set global statefulftp disable\n
Run Code Online (Sandbox Code Playgroud)\n\n