Ruby FTP extremely slow under Windows XP

2019-04-12 15:16发布

A couple of weeks ago, I wrote a simple Ruby script to test a couple of FTP commands in a Windows XP environment. Everything worked as expected, and I wasn't even aware of the time taken for the code to run (I'd guess 3-4 seconds at the very most.)

A few days ago, a much more involved Ruby application I'm developing started running very slowly. As I investigated the issue, I isolated the problem to the FTP commands. I've now rerun the original test script, and it takes over two minutes to run. Command-line FTP is essentially instantaneous.

No files in the ruby directory structure have been changed. I do not believe any new applications have been installed - certainly no other applications appear to be running.

Can anyone suggest why the following code should run so slowly? Manually timing the intervals between print statements suggest the nlst and ls take about 65 seconds each! The profiler gives a much more plausible total ms/call of 16 for nlst and 31 for ls.

require 'net/ftp'

Net::FTP.open("ip_redacted", "user_redacted", "password_redacted") do |ftp|
    ftp.chdir("dir_redacted")

    files = ftp.nlst
    print "files = #{files.sort!}\n"
    list = ftp.ls
    print "list = #{list}\n"

    file = "filename_redacted"

    size = ftp.size(file)
    print "size = #{size}\n"

end

标签: windows ruby ftp
3条回答
Animai°情兽
2楼-- · 2019-04-12 15:58
霸刀☆藐视天下
3楼-- · 2019-04-12 16:05

Try removing the #sort! (just puts "files = #{files}") since that can be fairly expensive if there's a bunch of files in the directory. This would account for the large lag around the #nlst and the #ls

查看更多
Deceive 欺骗
4楼-- · 2019-04-12 16:18

I had a similar issue and found Passive mode increased the speed, eg. ftp.passive=true.

查看更多
登录 后发表回答