2013-03-27 64 views
5

我曾嘗試使用FTP被動模式:
紅寶石FTP被動模式錯誤

require 'net/ftp' 
ftp = Net::FTP.new 
ftp.passive = true 
ftp.connect('mydomain.com') 
ftp.login 
filenames = ftp.nlst 

但已經得到了錯誤:

Errno::ETIMEDOUT: Connection timed out - connect(2) 

雖然與主動模式下,它工作正常

我使用紅寶石1.9.3。當我設置debuge模式:

ftp.debug_mode = true 

我看到:

**ftp.connect('mydomain.com')** 
connect: mydomain.com, 21 
get: 220---------- Welcome to Pure-FTPd [privsep] ---------- 
get: 220-You are user number 3 of 50 allowed. 
get: 220-Local time is now 11:43. Server port: 21. 
get: 220-IPv6 connections are also welcome on this server. 
get: 220 You will be disconnected after 15 minutes of inactivity. 
=> nil 
irb(main):103:0> ftp.login 
put: USER anonymous 
get: 230 Anonymous user logged in 
put: TYPE I 
get: 200 TYPE is now 8-bit binary 
=> true 
irb(main):104:0> filenames = ftp.nlst 
put: TYPE A 
get: 200 TYPE is now ASCII 
put: PASV 
get: 227 Entering Passive Mode (1,27,13,19,17,15) 
put: TYPE I 
get: 200 TYPE is now 8-bit binary 
Errno::ETIMEDOUT: Connection timed out - connect(2) 

而且我從Net::FTP主機發現,在功能transfercmd使用,從我的域名的IP地址不同!也許這是一個私人的IP地址?這裏有什麼問題?

+0

你確定你的服務器允許被動模式嗎?看起來像端口被關閉 – 2013-03-27 07:39:48

+0

你檢查天氣你的服務器提供了連接被動模式的能力嗎? – xyz 2013-03-27 07:39:49

+0

是的,我的服務器提供了連接被動模式的功能。我使用FTP客戶端進行了檢查。 – Vasilina 2013-03-27 07:45:03

回答

4

我已覆蓋方法makepasvNet::FTP它的工作原理!

module Net 
    class FTP 
    def makepasv # :nodoc: 
     if @sock.peeraddr[0] == "AF_INET" 
     #host, port = parse227(sendcmd("PASV")) #WAS! 
     host, port = parse229(sendcmd("EPSV")) 
     else 
     host, port = parse229(sendcmd("EPSV")) 
     end 
     return host, port 
    end 
    end 
end 
+1

不錯的工作,這個技巧,有一個補丁修復的地方! – 2014-05-25 20:32:58