Errno :: EPIPE:使用Net :: FTP断开管道

时间:2015-02-27 01:18:44

标签: ruby ftp net-ftp

this question类似,我可以连接甚至检查/更改工作目录,但调用list会引发Errno::EPIPE: Broken pipe错误。

到目前为止,我只是从终端(OS X)看到了这一点。我已经尝试了几个不同的主机,我已经验证了我可以使用FileZilla正常访问。我还验证了我可以通过常规的'命令行ftp会话列出文件。

这可能是防火墙问题吗?或者我的shell有问题吗?

以下是IRB会话的示例......

irb> ftp = Net::FTP.new 'host.domain.com' 
 => #<Net::FTP:0x007fc10d053ab8 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x007fc10d053a68>, @binary=true, @passive=false, @debug_mode=false, @resume=false, @sock=#<TCPSocket:fd 7>, @logged_in=false, @last_response="220 ESS FTP\n", @last_response_code="220"> 
irb> ftp.debug_mode = true
 => true 
irb> ftp.login 'user', '*********'
put: USER user
get: 331 Password required for user
put: PASS *********
get: 230 Logged on
put: TYPE I
get: 200 Type set to I
 => true 
irb> ftp.pwd
put: PWD
get: 257 "/" is current directory.
  => "/" 
irb> ftp.chdir 'Inventory'
put: CWD Inventory
get: 250 CWD successful. "/Inventory" is current directory.
irb> ftp.list
put: TYPE A
get: 200 Type set to A
put: PORT 10,142,96,98,199,111
put: TYPE I
Errno::EPIPE: Broken pipe
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:257:in `write'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:257:in `putline'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:334:in `block in voidcmd'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:333:in `voidcmd'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:162:in `send_type_command'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:151:in `binary='
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:180:in `ensure in with_binary'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:180:in `with_binary'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:477:in `block in retrlines'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:476:in `retrlines'
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/net/ftp.rb:722:in `list'
  from (irb):9
  from /Users/acobster/.rvm/rubies/ruby-1.9.3-p392/bin/irb:16:in `<main>'

请帮助,谢谢!

更新:我可以从远程服务器上的IRB会话中执行ftp.list ...

$ ssh myserver
server $ irb
irb> ftp = Net::FTP.new 'host.domain.com' 
=> #<Net::FTP:0x2b7d3c5edc80 @last_response="220 ESS FTP\n", @debug_mode=false, @mon_entering_queue=[], @sock=#<TCPSocket:0x2b7d3c5edb18>, @passive=false, @mon_count=0, @binary=true, @mon_owner=nil, @last_response_code="220", @resume=false, @mon_waiting_queue=[]>
irb> ftp.login 'user', 'pass'
=> "230 Logged on\n"
irb> ftp.pwd
=> "/"
irb> ftp.chdir 'Inventory'
=> nil
irb> ftp.list 
=> ["-r--r--r-- 1 ftp ftp         302301 Feb 26 20:27 inventory.zip", "-r--r--r-- 1 ftp ftp        1450282 Feb 26 20:24 InventoryWeb.txt"]

......但我不确定从中得出什么结论?我的本地版Ruby?它仍然是防火墙/外壳问题吗?

1 个答案:

答案 0 :(得分:3)

  

put:PORT 10,142,96,98,199,111

您在主动模式下使用FTP,私有IP地址为10.142.96.199。在主动模式下,服务器必须创建与主机的数据连接,而使用被动模式(PASV命令而不是PORT命令),客户端将连接到服务器。

由于服务器与主机不在同一个专用网络上(否则您将无法从远程系统连接到它),因此无法连接到10.142.96.98中的私有IP PORT命令,因为无法从Internet访问私有IP地址。服务器可能会意识到这一点,发回一些错误并关闭连接。您的FTP客户端可能会尝试发送另一个命令(如QUIT或ABOR)但由于服务器已经关闭了连接,因此该发送将导致EPIPE。

FileZilla的工作原理可能是因为它将使用被动模式而不是主动模式。要在Net :: FTP中使用被动模式,您必须设置ftp.passive = true

相关问题