在ruby中下载多个FTP文件,如d * .txt

前端之家收集整理的这篇文章主要介绍了在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

猜你在找的Ruby相关文章