我有这个失败的基本代码:
ftpconfighash = open("#{RAILS_ROOT}/config/ftp.yml") {|f| YAML.load(f) }
config = ftpconfighash[12345]
ftp = Net::FTP::new(config["host"])
ftp.login(config["username"], config["password"])
dir += "/" unless config["dir"].blank? or config["dir"].ends_with?("/")
remotename = File.basename(filename)
remotename = dir + remotename unless dir.blank?
if File.binary?(filename)
puts "PUTting binary file #{filename} to #{remotename}"
ftp.putbinaryfile(filename, remotename)
else
puts "PUTting ASCII file #{filename} to #{remotename}"
ftp.puttextfile(filename, remotename)
end
ftp.close
我已经验证我可以 ftp 到服务器并手动 PUT 一个文件。我还使用 irb 逐行浏览代码。我正在使用 XML 文件作为测试,因此“ftp.puttextfile”是失败的行。这是错误:
Net::FTPPermError: 500 Invalid PORT Command.
我不明白。我已经验证我确实可以放置这个文件,但是我不能用这个代码来做。
我将 ftp.debug_mode 设置为 true,这是 ftp.puttextfile 命令的输出:
put: TYPE A
get: 200 Type set to A.
put: PORT 10,0,1,20,198,170
get: 500 Invalid PORT Command.
Net::FTPPermError: 500 Invalid PORT Command.
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:243:in `getresp'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:251:in `voidresp'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:274:in `voidcmd'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:242:in `synchronize'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:272:in `voidcmd'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:287:in `sendport'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:295:in `makeport'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:328:in `transfercmd'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:424:in `retrlines'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/monitor.rb:242:in `synchronize'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:422:in `retrlines'
from /Users/me/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/net/ftp.rb:631:in `list'
from (irb):42
看起来 Ruby 正在尝试运行 FTP 服务器不理解的命令:
PORT 10,0,1,20,198,170
有什么方法可以抑制该命令,还是我错过了其他东西?