Home > Blockchain >  Download a file from FTP via proxy with Ruby
Download a file from FTP via proxy with Ruby

Time:02-18

I have an app running on Heroku, and I need to download a file from an FTP. But I need to do it using a fixed IP. I´m using www.quotaguard.com to have fixed IPs.

But I can´t get it working.

Does anyone has a Ruby example to download a file from an FTP via a proxy server (quotaguard).

Both the proxy server and the FTP require username and password.

I´ve tried everything, using Ruby. And also calling wget from system to initiate a download, but wget apparently doesn´t go via the proxy. Also checked many posts, but no success so far.

I´m using Ruby 2.4.5

Thanks for any comments.

CodePudding user response:

We've seen a few customers do this before with the socksify gem.

require 'socksify'

proxy = URI(ENV['QUOTAGUARDSTATIC_URL'])

TCPSocket::socks_username = proxy.user
TCPSocket::socks_password = proxy.password
Socksify::proxy(proxy.hostname, 1080) do |soc|
  # do your FTP stuff in here
end

If that doesn't do it, post the errors you're seeing and we'll help get this running for you.

CodePudding user response:

Thank you QuotaGuard. Socksify is not maintained and really old, we gave it a try but didn´t want to spend much time on it.

We actually managed to get this working with curl. You can call it within Heroku as well.

Here´s the command in case anyone wonders.

curl -x socks5h://socksproxyurl 'ftp://theftp/some.pdf' --user "ftp_user:ftp_pass" -o some.pdf
  • Related