Access ftp-server through proxy

K

Kristian Sørensen

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.
 
G

gabriele renzi

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
 
K

Kristian Sørensen

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?
 
K

Kristian Sørensen

Clifford said:
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.domain" 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:p[email protected]/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:[email protected]', 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
 
K

Kristian Sørensen

Clifford said:
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:[email protected]".

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.
 
K

Kristian Sørensen

Clifford said:
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:[email protected]".

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.
 
K

Kristian Sørensen

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



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.
 
T

Thomas Fini Hansen

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:[email protected]', 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)
}
}
-----

Tried this?

Net::HTTP.start('the.proxy.com', 80) { |http|
response, data = http.get('ftp://anonymous:[email protected]" +
"/pub/gnu/mc/mc-4.5.55.tar.gz', nil)
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top