前端之家收集整理的这篇文章主要介绍了
在ruby中下载多个FTP文件,如d * .txt,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要连接到一个ftp
站点并下载一堆名为D * .txt的
文件(最多6个).
你能帮我用
Ruby编写
代码吗?
以下
代码只是
ftp = Net::FTP::new("ftp_server_site")
ftp.login("user","pwd")
ftp.chdir("/RemoteDir")
fileList= ftp.nlst
ftp.getbinaryfile(edi,edi)
ftp.close
谢谢
最简单的
方法是循环遍历fileList中的
文件列表.
这是一个例子(未经测试):
ftp = Net::FTP::new("ftp_server_site")
ftp.login("user","pwd")
ftp.chdir("/RemoteDir")
fileList = ftp.list('D*.txt')
fileList.each do |file|
ftp.gettextfile(file)
end
ftp.close
希望这可以帮助.
原文链接:https://www.f2er.com/ruby/267321.html