我试图使用FTP与被动模式:
require 'net/ftp'
ftp = Net::FTP.new
ftp.passive = true
ftp.connect('mydomain.com')
ftp.login
filenames = ftp.nlst
Run Code Online (Sandbox Code Playgroud)
但是有错误:
Errno::ETIMEDOUT: Connection timed out - connect(2)
Run Code Online (Sandbox Code Playgroud)
虽然有活动模式但它工作正常!
我用ruby 1.9.3.当我设置debuge模式时:
ftp.debug_mode = true
Run Code Online (Sandbox Code Playgroud)
我知道了:
**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)
Run Code Online (Sandbox Code Playgroud)
另外我还发现,在功能transfercmd从Net::FTP主机使用,从我的域名的IP地址不同!也许这是一个私人IP地址?这有什么不对?
我已经重写方法makepasv从Net::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
Run Code Online (Sandbox Code Playgroud)