我有一个自动脚本,它使用 lftp 连接到服务器并下载文件。我已经成功运行了该脚本好几次(所以我知道理论上它是有效的)。最近,我怀疑我们在连接远程服务器时遇到了问题(我们不拥有它,所以我无法验证它是“启动”还是“关闭”)。
我知道 lftp 通过 ssh 连接。当我运行 lftp 程序时,它只是不断尝试重新连接。
/bin/lftp -d -e 'set sftp:connect-program "ssh -a -x -i /home/username/.ssh/id_rsa -o "ConnectionAttempts=1" -o "ConnectTimeout=10" -o "BatchMode=yes" -o "ServerAliveInterval=15""; set cmd:fail-exit on; set dns:max-retries 3; set dns:fatal-timeout 20; set net:max-retries 3; set net:timeout 25; set ssl:key-file /home/username/.ssh/id_rsa; set xfer:clobber on; get OUT/remote_filename.txt -o remote_filename.txt; bye' -uremoteusername,xyz sftp://sftp.remoteserver.com
---- Running connect program (ssh -a -x -i /home/username/.ssh/id_rsa -o ConnectionAttempts=1 -o ConnectTimeout=10 -o BatchMode=yes -o ServerAliveInterval=15 -s -l remoteusername sftp.remoteserver.com sftp)
---> sending a packet, length=5, type=1(INIT), id=0
<--- Connection timed out during banner exchange
**** Peer closed connection
---- Disconnecting
---- Running connect program (ssh -a -x -i /home/username/.ssh/id_rsa -o ConnectionAttempts=1 -o ConnectTimeout=10 -o BatchMode=yes -o ServerAliveInterval=15 -s -l remoteusername sftp.remoteserver.com sftp)
---> sending a packet, length=5, type=1(INIT), id=0
<--- Connection timed out during banner exchange
**** Peer closed connection
---- Disconnecting
---- Running connect program (ssh -a -x -i /home/username/.ssh/id_rsa -o ConnectionAttempts=1 -o ConnectTimeout=10 -o BatchMode=yes -o ServerAliveInterval=15 -s -l remoteusername sftp.remoteserver.com sftp)
---> sending a packet, length=5, type=1(INIT), id=0
<--- Connection timed out during banner exchange
**** Peer closed connection
---- Disconnecting
---- Running connect program (ssh -a -x -i /home/username/.ssh/id_rsa -o ConnectionAttempts=1 -o ConnectTimeout=10 -o BatchMode=yes -o ServerAliveInterval=15 -s -l remoteusername sftp.remoteserver.com sftp)
---> sending a packet, length=5, type=1(INIT), id=0
<--- Connection timed out during banner exchange
**** Peer closed connection
---- Disconnecting
---- Running connect program (ssh -a -x -i /home/username/.ssh/id_rsa -o ConnectionAttempts=1 -o ConnectTimeout=10 -o BatchMode=yes -o ServerAliveInterval=15 -s -l remoteusername sftp.remoteserver.com sftp)
---> sending a packet, length=5, type=1(INIT), id=0
<--- Connection timed out during banner exchange
**** Peer closed connection
---- Disconnecting
---- Running connect program (ssh -a -x -i /home/username/.ssh/id_rsa -o ConnectionAttempts=1 -o ConnectTimeout=10 -o BatchMode=yes -o ServerAliveInterval=15 -s -l remoteusername sftp.remoteserver.com sftp)
---> sending a packet, length=5, type=1(INIT), id=0
<--- Connection timed out during banner exchange
**** Peer closed connection
---- Disconnecting
Interrupt
你可以看到,在我手动关闭它之前,它尝试重新连接至少 6 次。它似乎忽略了 3 次最大重试次数。
如果我手动测试底层 ssh 连接,似乎会失败(尝试 1 次后):
ssh -v -v -v -a -x -i /home/username/.ssh/id_rsa -o ConnectionAttempts=1 -o ConnectTimeout=10 -o BatchMode=yes -o ServerAliveInterval=15 -s -l remoteusername sftp.remoteserver.com sftp
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 60: Applying options for *
debug1: Executing proxy command: exec /usr/bin/sss_ssh_knownhostsproxy -p 22 sftp.remoteserver.com
debug3: timeout: 10000 ms remain after connect
debug1: permanently_drop_suid: 1839400042
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/username/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /home/username/.ssh/id_rsa type 1
debug1: identity file /home/username/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
Connection timed out during banner exchange
因此,问题似乎出在 ssh 的初始设置上。lftp 似乎没有意识到 ssh 以某种方式失败了,因此它继续尝试设置连接。
有没有办法让两者很好地发挥作用?我想避免我的脚本在尝试建立连接时永远挂起。
谢谢!