使用Ruby模糊FTP服务器
嘿,我是Ruby的新手,并试图通过将一些编程从一种语言移植到另一种语言来学习。现在我正在使用Ruby中的FTP模糊器来镜像这个perl脚本:
use Net::FTP;
$target = "192.168.37.128";
$buffer = "Ax20";
$buffer .= "A" x 512;
$ftp = Net::FTP->new($target, Debug => 0, Timeout => 5)
or die "Cannot connect to $host: $@ n";
$ftp->login("anonymous",'anonymous@nowhere.com')
or die "Couldn't log in: $@n";
$ftp->list($buffer);
$ftp->quit;
这是我的Ruby等价物:
require 'net/ftp'
buffer = 'Ax20'
buffer = (buffer + ('A'*512))
ftp = Net::FTP.open('127.0.0.1','anonymous','anonymous')
ftp.login
ftp.list(buffer)
ftp.quit
当我运行该程序时,我收到以下错误:
C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:241:in `readline': end of file reached (EOF
Error)
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:241:in `getline'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:251:in `getmultiline'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:265:in `getresp'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:281:in `voidresp'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:304:in `block in voidcmd'
from C:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:302:in `voidcmd'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:155:in `send_type_command'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:149:in `binary='
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:168:in `ensure in with_binary'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:168:in `with_binary'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:440:in `block in retrlines'
from C:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:439:in `retrlines'
from C:/Ruby192/lib/ruby/1.9.1/net/ftp.rb:682:in `list'
from ftpcrash.rb:10:in `<main>'
我已经将问题追溯到了ftp.list(buffer)
系列,但是无法提出一个Ruby解决方案,它将完成perl中的$ftp->list($buffer)
。
建议?
没有找到相关结果
已邀请:
3 个回复
骨乏唯瓜
疾桓
源代码判断,当ftp库试图从服务器获取响应并且响应为空时,会引发此异常。 您应该将此命令包装在
(或只是
)并相应地处理错误。
棠媳鳖
保持安全;)