[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Access ftp-server through proxy

Kristian Sørensen

11/10/2003 9:37:00 PM



Hi!

Is it possible to download files from an ftp-server through a
proxy-server, in a ruby-script? If so, do you have an example or url to
api specification?

Cheers, Kristian.

12 Answers

gabriele renzi

11/10/2003 10:10:00 PM

0

il Mon, 10 Nov 2003 22:36:35 +0100, Kristian Sørensen <ks@cs.auc.dk>
ha scritto::

>
>
>Hi!
>
>Is it possible to download files from an ftp-server through a
>proxy-server, in a ruby-script? If so, do you have an example or url to
>api specification?

from the pickaxe's doc for Net::FTP

aSession.connect( host, port=FTP_PORT )

Establishes an FTP connection to host, optionally overriding the
default port. If the environment variable SOCKS_SERVER is set, sets up
the connection through a SOCKS proxy. Raises an exception (typically
Errno::ECONNREFUSED) if the connection cannot be established



>Cheers, Kristian.

Kristian Sørensen

11/10/2003 10:45:00 PM

0



Hi, thanks for your answer :)

I saw the below part, but was not clear enough in my question:

- Internet browsers is able to use e.g. regular squid proxy to make ftp
connections. That was what I was after. It isn't too many places a socks
server is available (not that I know of anyway ;)

Is it possible to do something like the browsers, without socks?

gabriele renzi wrote:
> il Mon, 10 Nov 2003 22:36:35 +0100, Kristian Sørensen <ks@cs.auc.dk>
> ha scritto::
>
>
>>
>>Hi!
>>
>>Is it possible to download files from an ftp-server through a
>>proxy-server, in a ruby-script? If so, do you have an example or url to
>>api specification?
>
>
> from the pickaxe's doc for Net::FTP
>
> aSession.connect( host, port=FTP_PORT )
>
> Establishes an FTP connection to host, optionally overriding the
> default port. If the environment variable SOCKS_SERVER is set, sets up
> the connection through a SOCKS proxy. Raises an exception (typically
> Errno::ECONNREFUSED) if the connection cannot be established
>
>
>
>
>>Cheers, Kristian.
>
>



Clifford Heath

11/10/2003 11:10:00 PM

0

Kristian Sørensen wrote:
> - Internet browsers is able to use e.g. regular squid proxy to make ftp
> connections. That was what I was after. It isn't too many places a socks
> server is available (not that I know of anyway ;)

You make an HTTP proxy request, using an FTP URL.

An HTTP proxy request differs from a normal HTTP request
in that the GET line contains "http://host.do... at the
start of the URL string. Just replace the http with ftp,
add whatever username/password you need, and Squid will
do the FTP for you. The request line looks like:

GET ftp://user:password@host.domain/pub/some_file HTTP/1.0

I haven't tried to do this with Ruby's http though...

Clifford.

Kristian Sørensen

11/11/2003 2:28:00 AM

0



Clifford Heath wrote:
> Kristian Sørensen wrote:
>
>> - Internet browsers is able to use e.g. regular squid proxy to make
>> ftp connections. That was what I was after. It isn't too many places a
>> socks server is available (not that I know of anyway ;)
>
>
> You make an HTTP proxy request, using an FTP URL.
>
> An HTTP proxy request differs from a normal HTTP request
> in that the GET line contains "http://host.do... at the
> start of the URL string. Just replace the http with ftp,
> add whatever username/password you need, and Squid will
> do the FTP for you. The request line looks like:
>
> GET ftp://user:password@host.domain/pub/some_file HTTP/1.0
Okay, that's sounds easy, but I can't get it to work. Can you complete a
ftp-download example?

I have tried with the following (including variants of it), but can't
get it to work:
-----
#!/usr/bin/env ruby
require 'net/http'

Net::HTTP.start('ftp://anonymous:anonymous@ftp.sunsite.dk', 21) { |http|
response, data = http.get('/pub/gnu/mc/mc-4.5.55.tar.gz', nil)

File.open("mc.tgz", "wb") { |f|
f.write(data)
}
}
-----


I get the error trace:
-----
/pack/ruby-1.8.0/lib/ruby/1.8/net/protocol.rb:84:in `initialize':
getaddrinfo: Name or service not known (SocketError)
from /pack/ruby-1.8.0/lib/ruby/1.8/net/protocol.rb:84:in `new'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/protocol.rb:84:in `connect'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/protocol.rb:83:in `timeout'
from /pack/ruby-1.8.0/lib/ruby/1.8/timeout.rb:55:in `timeout'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/protocol.rb:83:in `connect'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/protocol.rb:65:in `initialize'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/http.rb:422:in `open'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/http.rb:422:in `do_start'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/http.rb:409:in `start'
from /pack/ruby-1.8.0/lib/ruby/1.8/net/http.rb:324:in `start'
from ./ftpget.rb:4
-----

/KS

Clifford Heath

11/11/2003 4:29:00 AM

0

Kristian Sørensen wrote:
> Okay, that's sounds easy, but I can't get it to work. Can you complete a
> ftp-download example?

I don't know if it's possible with Ruby 1.6. Your example doesn't work
because the "start" method expects a DNS-resolvable name, but you
gave it "ftp://anonymous:anonymous@ftp.sunsite.dk".

I don't recall seeing this in 1.6, but 1.8 has Net::HTTP.Proxy:

#! /usr/bin/env ruby
require 'net/http'

Net::HTTP::Proxy('webproxy.local', 3128).start('ftp.netscape.com') { |http|
response, data = http.get('/')
$stdout.write(data)
}

Works a treat here.

Kristian Sørensen

11/11/2003 3:30:00 PM

0



Clifford Heath wrote:
> Kristian Sørensen wrote:
>
>> Okay, that's sounds easy, but I can't get it to work. Can you complete
>> a ftp-download example?
>
>
> I don't know if it's possible with Ruby 1.6. Your example doesn't work
> because the "start" method expects a DNS-resolvable name, but you
> gave it "ftp://anonymous:anonymous@ftp.sunsite.dk".
>
> I don't recall seeing this in 1.6, but 1.8 has Net::HTTP.Proxy:
>
> #! /usr/bin/env ruby
> require 'net/http'
>
> Net::HTTP::Proxy('webproxy.local', 3128).start('ftp.netscape.com') { |http|
> response, data = http.get('/')
> $stdout.write(data)
> }
>
> Works a treat here.
That did the job. Thanks a lot!! ;)

KS.


Kristian Sørensen

11/12/2003 3:27:00 PM

0



Clifford Heath wrote:
> Kristian Sørensen wrote:
>
>> Okay, that's sounds easy, but I can't get it to work. Can you complete
>> a ftp-download example?
>
>
> I don't know if it's possible with Ruby 1.6. Your example doesn't work
> because the "start" method expects a DNS-resolvable name, but you
> gave it "ftp://anonymous:anonymous@ftp.sunsite.dk".
>
> I don't recall seeing this in 1.6, but 1.8 has Net::HTTP.Proxy:
>
> #! /usr/bin/env ruby
> require 'net/http'
>
> Net::HTTP::Proxy('webproxy.local', 3128).start('ftp.netscape.com') { |http|
> response, data = http.get('/')
> $stdout.write(data)
> }
>
> Works a treat here.
Hi again!

As I wrote earlier, it seems to work nicely. However the reason for
this, is that a webserver is also providing an interface to
ftp.netscape.com. The request created by Ruby is an http request on port
80, not a ftp request.

Fortunately the all-over solution just poped into my head: use wget...
`wget --passive-ftp #{server}:#{pathAndFile}`


Cheers, KS.



Clifford Heath

11/12/2003 11:57:00 PM

0

Kristian Sørensen wrote:
> As I wrote earlier, it seems to work nicely. However the reason for
> this, is that a webserver is also providing an interface to
> ftp.netscape.com.

Ouch, you're right! I should have realised that my example didn't
actually request ftp protocol.

> Fortunately the all-over solution just poped into my head: use wget...

Yup, but that's pretty sucky. Will see if I can see how to extend
Net::HTTP to do the right thing. The problem is in 'module ProxyDelta',
the edit_class method, which has http:// hard-wired, sigh.

Kristian Sørensen

11/13/2003 3:06:00 PM

0



Clifford Heath wrote:
> Kristian Sørensen wrote:
>
>> As I wrote earlier, it seems to work nicely. However the reason for
>> this, is that a webserver is also providing an interface to
>> ftp.netscape.com.
>
>
> Ouch, you're right! I should have realised that my example didn't
> actually request ftp protocol.
>
>> Fortunately the all-over solution just poped into my head: use wget...
>
>
> Yup, but that's pretty sucky. Will see if I can see how to extend
> Net::HTTP to do the right thing. The problem is in 'module ProxyDelta',
> the edit_class method, which has http:// hard-wired, sigh.
I would not say that wget sucks .. ? :) But - builtin ruby support would
be nice though :)

Cheers, KS.




Martin DeMello

11/13/2003 4:06:00 PM

0

Clifford Heath <cjh_nospam@managesoft.com> wrote:
> Kristian S?rensen wrote:
>
>> Fortunately the all-over solution just poped into my head: use wget...
>
> Yup, but that's pretty sucky. Will see if I can see how to extend
> Net::HTTP to do the right thing. The problem is in 'module ProxyDelta',
> the edit_class method, which has http:// hard-wired, sigh.

There's a ruby-curl, which might help (or might not - it's pre-alpha
according to the webpage).

http://rox-ruby.sourceforge.net/cm...

martin