Peter Booth
2/27/2007 2:32:00 AM
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>
>
>
>