Ruby : Establish a connection to an FTP server via a proxy



Written by Anthony Heukmes on Wed Apr 08 12:17:03 UTC 2009

1 comment



By default, it's not possible to connect to an FTP server via a proxy using the Net::FTP Ruby library.
To use your proxy, you have to send RAW commands to the server :

@ftp = Net::FTP.new

@ftp.connect("proxy_address")
@ftp.sendcmd("USER ftp_login@ftp_address proxy_login")
@ftp.sendcmd("PASS ftp_password")
@ftp.sendcmd("ACCT proxy_password")
@ftp.passive = true


Take the time to replace addresses and credentials by yours.
This code considers that access to your proxy server is secured by login/password.

Bookmark and Share

Add a comment



1 comment for this article



This is how I got it working

require 'net/ftp'
ftp = Net::FTP.new
ftp.connect("ftp-proxy-name", port_number)
ftp.passive = true
ftp.login("username@location_ip", "password")
ftp.chdir('folder/folder/folder')
puts ftp.list


Written by ftp-kid on Mon Feb 15 10:16:20 UTC 2010