Net::FTP hangs

T

Timothy Hunter

Running ruby 1.8.5 (2006-08-25) on Mac OS X 10.4.8.

I'm trying to get this example from the _Ruby_Cookbook_ to work, but it
hangs in the ftp.list method. What am I doing wrong?

#!/usr/bin/env ruby

require 'net/ftp'

ftp = Net::FTP.open("ftp.ibiblio.org") do |ftp|
ftp.login
ftp.chdir("pub/linux/")
ftp.list('*Linux*') {|file| puts file}
end

Eventually this will fail with these messages:

/opt/local/lib/ruby/1.8/net/ftp.rb:241:in `getresp': 425 Unable to build
data connection: Connection timed out (Net::FTPTempError)
from /opt/local/lib/ruby/1.8/net/ftp.rb:264:in `sendcmd'
from /opt/local/lib/ruby/1.8/monitor.rb:238:in `synchronize'
from /opt/local/lib/ruby/1.8/net/ftp.rb:262:in `sendcmd'
from /opt/local/lib/ruby/1.8/net/ftp.rb:336:in `transfercmd'
from /opt/local/lib/ruby/1.8/net/ftp.rb:421:in `retrlines'
from /opt/local/lib/ruby/1.8/monitor.rb:238:in `synchronize'
from /opt/local/lib/ruby/1.8/net/ftp.rb:419:in `retrlines'
from /opt/local/lib/ruby/1.8/net/ftp.rb:625:in `list'
from ftptest.rb:8
from /opt/local/lib/ruby/1.8/net/ftp.rb:115:in `open'
from ftptest.rb:5

I can connect to this server and issue similar commands using the
command line ftp client:

ruby$ ftp
ftp> open ftp.ibiblio.org
Connected to ibiblio.org.
220 ProFTPD Server (Bring it on...)
Name (ftp.ibiblio.org:tim): anonymous
331 Anonymous login ok, send your complete email address as your password.
Password:
230-
Welcome to ftp.ibiblio.org, the public ftp server of ibiblio.org. We
hope you find what you're looking for.

If you have any problems or questions, please send email to

(e-mail address removed)

Thanks!

230 Anonymous access granted, restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub/linux
250 CWD command successful
ftp> ls *Linux*
229 Entering Extended Passive Mode (|||60724|)
150 Opening ASCII mode data connection for file list
-rw-r--r-- 1 (?) users 531113 Feb 26 11:06 00-find.Linux.gz
-rw-rw-r-- 1 (?) admin 73 Mar 9 2001 How-do-I-get-Linux
226 Transfer complete.
ftp>
 
P

Peter Booth

Works for me from script or in irb. I'd be suspicious about your name
resolution

I'd suggest breaking this down - do any of the net examples work?
Try an http example
Try writing a dns client

Good luck

pboothOSXhome:~ pbooth$ uname -a
Darwin pboothOSXhome.local 8.8.2 Darwin Kernel Version 8.8.2: Thu Sep
28 20:43:26 PDT 2006; root:xnu-792.14.14.obj~1/RELEASE_I386 i386 i386
pboothOSXhome:~ pbooth$
pboothOSXhome:~ pbooth$ ruby ftpscript.rb
-rw-r--r-- 1 (?) users 531113 Feb 26 11:06 00-find.Linux.gz
-rw-rw-r-- 1 (?) admin 73 Mar 9 2001 How-do-I-get-
Linux
pboothOSXhome:~ pbooth

Last login: Mon Feb 26 21:18:06 on console
Welcome to Darwin!
pboothOSXhome:~ pbooth$ irb
irb(main):001:0> require 'net/ftp'
=> true
irb(main):002:0> ftp = Net::FTP.open("ftp.ibiblio.org") do |ftp|
irb(main):003:1* ftp.login
irb(main):004:1> ftp.chdir("pub/linux")
irb(main):005:1> ftp.list('*Linux*') {|f| puts f}
irb(main):006:1> end
-rw-r--r-- 1 (?) users 531113 Feb 26 11:06 00-find.Linux.gz
-rw-rw-r-- 1 (?) admin 73 Mar 9 2001 How-do-I-get-
Linux
=> nil
irb(main):007:0> quit
pboothOSXhome:~ pbooth$ ruby -v
ruby 1.8.5 (2006-08-25) [powerpc-darwin8.8.0]
pboothOSXhome:~ pbooth$
 
T

Timothy Hunter

Peter said:
Works for me from script or in irb. I'd be suspicious about your name
resolution

I'd suggest breaking this down - do any of the net examples work?
Try an http example
Try writing a dns client
open-uri works to retrieve a web page via a url. curl works. I installed
the most recent version of Ruby but it didn't help.
 
A

ara.t.howard

open-uri works to retrieve a web page via a url. curl works. I installed the
most recent version of Ruby but it didn't help.

ftp.passive = true

??

-a
 
A

ara.t.howard

That did the trick, Ara! Thanks! Now the question is, why?

most client software auto negotiates this these days, like curl, which is very
smart. ruby's ftp lib doesn't. i always forget which is which between
passive and active, but i think people are moving toward passive because it
plays nice with firewalls.

http://slacksite.com/other/ftp.html

regards.

-a
 
T

Timothy Hunter

most client software auto negotiates this these days, like curl, which
is very
smart. ruby's ftp lib doesn't. i always forget which is which between
passive and active, but i think people are moving toward passive
because it
plays nice with firewalls.

http://slacksite.com/other/ftp.html

regards.

-a
Thank you for the education, Ara. My ignorance of FTP is a bit less vast
than before, thanks to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top