我正在使用 net-sftp gem 将文件上传到 ftp 服务器。这是我的代码:
require "net/sftp"
Net::SFTP.start(url, username, password: password) do |sftp|
sftp.upload!(file_path, "/")
end
它只是挂在上传行,并最终因错误而超时Net::SSH::Disconnect: connection closed by remote host
。我可以使用 FileZilla 使用相同的 url、用户名和密码通过 SFTP 连接。
我也尝试运行非块版本verbose: :debug
:
sftp = Net::SFTP.start(test.ftphost.com, ftp_username, password: ftp_password, verbose: :debug)
^ 这产生的输出表明连接良好:
I, [2015-04-29T10:32:51.381339 #25769] INFO -- net.ssh.connection.session[3fc8a502c24c]: channel_success: 0 D, [2015-04-29T10:32:51.381429 #25769] DEBUG -- net.sftp.session[3fc8a5025d70]: sftp subsystem successfully started
然后我输入了以下内容:
sftp.upload!("/Users/marina/Desktop/test.png", "/")
输出像这样卡住:
I, [2015-04-29T10:32:55.035471 #25769] INFO -- net.sftp.session[3fc8a5025d70]: sending open packet (0)
D, [2015-04-29T10:32:55.035740 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: queueing packet nr 12 type 94 len 44
D, [2015-04-29T10:32:55.036149 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: sent 68 bytes
D, [2015-04-29T10:32:55.119070 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: read 52 bytes
D, [2015-04-29T10:32:55.119356 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: received packet nr 11 type 96 len 28
I, [2015-04-29T10:32:55.119470 #25769] INFO -- net.ssh.connection.session[3fc8a502c24c]: channel_eof: 0
D, [2015-04-29T10:32:55.195747 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: read 120 bytes
D, [2015-04-29T10:32:55.196037 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: received packet nr 12 type 98 len 44
I, [2015-04-29T10:32:55.196176 #25769] INFO -- net.ssh.connection.session[3fc8a502c24c]: channel_request: 0 exit-status false
D, [2015-04-29T10:32:55.196445 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: received packet nr 13 type 97 len 28
I, [2015-04-29T10:32:55.196527 #25769] INFO -- net.ssh.connection.session[3fc8a502c24c]: channel_close: 0
D, [2015-04-29T10:32:55.196743 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: queueing packet nr 13 type 97 len 28
D, [2015-04-29T10:32:55.196806 #25769] DEBUG -- net.sftp.session[3fc8a5025d70]: sftp channel closed
D, [2015-04-29T10:32:55.197022 #25769] DEBUG -- tcpsocket[3fc8a4cf464c]: sent 52 bytes
有任何想法吗?