Setting up proxy with ftp with Python

python ftp download
python ftp list files
python ftp upload
python ftp over proxy
ftp nlst
python ftp server
python requests-ftp
python read file from ftp server

We are trying to develop a Python module that will hit an FTP server and download files to my local machine. When we try to run the FTP portion of the module it is timing out.

We have a proxy server (let's call it "") to handle this and when using an FTP client like FileZilla or Windows Explorer to access FTP sites we are successful.

Let's call the ftp site "". User name is "papa". Password is "tango123".

So far we have:

Proxy =


User = papa

PW = tango123 

The above are not real entities so if you want to swap them out for real ones, be my guest.

I need a module to first load the proxy service then run the FTP portion.

I am running Python 2.7.

I have searched around and have this code so far. The OP said it is just a short module to test connection to FTP and read one file.

(Note: I have intentionally put # in a lot of places to show when I don't know to fill in, or other reasons):

import urllib2
# I have filled in the proxy info
proxy_host = ''

# I don't think this needs any modification, right?  
proxy_handler = urllib2.ProxyHandler({'ftp': proxy_host})

# ditto here 
proxy_auth_handler = urllib2.ProxyBasicAuthHandler() 

# now here is where I am unsure what to put; 
# also, I really need FTP user and FTP password, and NOT Proxy... 
# so what do I need to change here?
proxy_auth_handler.add_password(None, proxy_host, proxy_user, proxy_passwd) 
opener_thru_proxy = urllib2.build_opener(proxy_handler, proxy_auth_handler)

# I filled in this part
conn ='') 

# I don't believe I need to change this, right?

ftp-proxy · PyPI, A http to ftp proxy server application. pip install ftp-proxy test pipenv run python sdist pipenv run python bdist_wheel pipenv run  6 Answers 6. As per this source. Depends on the proxy, but a common method is to ftp to the proxy, then use the username and password for the destination server. E.g. for In Python code: the link in the above answer is 404. The "anonymous at" part is pure fiction.

The question is a little bit out-dated, but I didn't find any recent solution myself so I figured I would provide the solution I found. In my case the office proxy requires credentials so those are included in the solution. I would presume that you can just remove the proxy_user and proxy_passwd if your proxy does not require credentials. The code I got working in Python 3.6 is:

from ftplib import FTP

ftp = FTP("")
ftp.login(user='ftp_user@ftp_host proxy_user', passwd='ftp_passwd', acct='proxy_passwd')

# Do whatever you need on the FTP server here


I hope this helps.

ftp-proxy-client · PyPI, python client for ftp-proxy server. pip install ftp-proxy-client. Copy PIP An FTP client for [ftp-proxy]( FTP stands for File Transfer Protocol and is the de facto standard for transferring files from one place to another. Python has a fully mature FTP library that any script can utilize with a simple import statement.

Adding this as it's one of the top results and struggled to find a solution.

If your proxy is a HTTP proxy and you need to authenticate it then this is how:

import socks
import socket

socket.socket = socks.socksocket
ftp = FTP(ftp_host)

Otherwise for a FTP Proxy Martin's answer works. You can see the behaviour in FileZilla for FTP proxies too and that'll help to code for your requirements

Hope this helps someone!

ftplib — FTP protocol client, For more information on FTP (File Transfer Protocol), see Internet RFC 959. Here's a sample It is rarely needed to specify a different port number. This function  environment is set up for it (http_proxy, etc. environment variables), you don't need to supply a ProxyHandler (of course, if your environ. *isn't*, then you do need to supply one, to give it the proxy details). You don't need Request objects (unless you want to add headers to a Request, or pass Requests around). You don't need to

FTP over http proxy in Python 3 - learnpython, I tried doing some of the workarounds putting the proxy as the FTP server address for FTPlib, but I can't get it to work. I also tried Plus most of the examples I find online are 5+ years old in Python 2. Log in or sign up to leave a comment. Adam Hi, I am using a script written in Python. For some reasons I should pass the fireware by proxy setting. But it seems not work when I set the 'http_proxy' 'ftp_proxy' environment variable.

Using Python to Fetch Files from an FTP Server, How do I connect to an FTP server using python? The ftplib module in Python allows you to write Python programs that perform a variety of automated FTP jobs. You can easily connect to a FTP server to retrieve files and process them locally. To use the ftplib module in Python, you first have to import it into your script.

MLSD FTP command, , directory information is sent to the client over a previously established data connection. Fortunately, the pip installer works for Windows as well, allowing the installation of Python packages automatically with a simple command (pip install package_name). But at work, we’re behind a proxy server so I have to set the HTTP_PROXY environment variable first before pip can connect to download the packages.

  • Can you update your question with the error stack trace?
  • Thanks for your input. I will try to implement this today and will get back to you with the results!
  • I think we may have a slight miscommunication. When I started to insert the code into the module, I realized that we are missing the FTP address (section #2). So I wanted to reconvey the intended sequence of events.
  • Sorry, got cut off due to time limit. Anyway, the miscommunication is my fault. The FTP server is not ours, it belongs to our vendor and we have no control over it. Our corporate IT department has done something to limit outgoing FTP requests from behind our firewall and that is why I need a way to circumvent the limitation using our proxy server instead. I've used the proxy server effectively with an FTP client (FileZilla) so I know once I can get the Proxy initialized it can pass through.
  • Therefore, here is the sequence I believe needs to be followed: 1) Create proxy event handler (using no authentication is required yet at this point. 2) Create FTP handler to info which consists of a) FTP address [], b) User [papa] and c) PW [tango123] to log in to FTP server. IOW, the authentication takes place AFTER the proxy is initialized. I hope this clarifies it some.
  • Oh I see now. Let me work on that a bit and update my answer.