[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Net::FTP hangs

Tim Hunter

2/27/2007 12:20:00 AM


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

ftpkeeper@ibiblio.org

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>



7 Answers

Peter Booth

2/27/2007 2:32:00 AM

0

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$

On Feb 26, 2007, at 7:20 PM, Timothy Hunter wrote:

>
> 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
> ftpkeeper@ibiblio.org
> 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>
>
>
>


Tim Hunter

2/27/2007 11:53:00 PM

0

Peter Booth wrote:
> 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.

Ara.T.Howard

2/28/2007 12:03:00 AM

0

Tim Hunter

2/28/2007 11:04:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Wed, 28 Feb 2007, Timothy Hunter wrote:
>
>> Peter Booth wrote:
>>> 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.
>>
>
> ftp.passive = true
>
> ??
>
> -a
That did the trick, Ara! Thanks! Now the question is, why?

Andrew Kreps

2/28/2007 11:11:00 PM

0

On 2/28/07, Timothy Hunter <TimHunter@nc.rr.com> wrote:
> ara.t.howard@noaa.gov wrote:
> >
> > ftp.passive = true
> >
> > ??
> >
> > -a
> That did the trick, Ara! Thanks! Now the question is, why?
>
>

This has to do with the proliferation of FTP servers hidden behind
firewalls over the last few years. There's a fairly detailed
explanation here:

http://slacksite.com/othe...

If you'd like more information, just google passive FTP.

Ara.T.Howard

2/28/2007 11:11:00 PM

0

Tim Hunter

3/1/2007 2:15:00 AM

0

ara.t.howard@noaa.gov wrote:
> 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/othe...
>
> regards.
>
> -a
Thank you for the education, Ara. My ignorance of FTP is a bit less vast
than before, thanks to you.