Why can wget use proxy environment variables but ftplib cannot?

786 views Asked by At

I'm really confused, I'm sure I'm missing something simple, but I can't understand why setting proxy environment variables works for some functions but not others. Is it that the libraries respond to these variables differently?

For example, I'm round-tripping a file via ftp. When I download with wget, I set the proxy environment variables and it downloads, but then say I want to put it back using ftplib, it gets [Errno 11001], do I need to specifically pass these proxy details through ftplib?

Say I set it up this way, I can download the file just fine:

# setup proxy
os.environ["ftp_proxy"] = 
"http://****:****@proxyfarm.****.com:8080"
os.environ["http_proxy"] = 
"http://****:****@proxyfarm.****.com:8080"
os.environ["https_proxy"] = 
"http://****:****@proxyfarm.****.com:8080"

src = "ftp://****:****@ftp.blackrock.com/****/****.csv"
out = "C:\\outFolder\\outFileName.txt" # out is optional

# create output folder if it doesn't exists
outFolder, _ = os.path.split( out )
try:
    os.makedirs(outFolder)
except OSError as exc: # Python >2.5
    if exc.errno == errno.EEXIST and os.path.isdir(outFolder):
        pass
    else: raise

# download
filename = wget.download(src, out)

Now immediately below that, I switch to ftplib, I get the [Errno 11001], do I need to reset the proxy parameters for ftplib specifically?

session = ftplib.FTP('ftp.blackrock.com','****','****')
file = open(filename,'rb')                  # file to send
session.storbinary('STOR '+ remotePath + filename, file)     # send the file
file.close()                                    # close file and FTP
session.quit()
1

There are 1 answers

1
Martin Prikryl On BEST ANSWER

The ftp_proxy (and the others) is a proprietary feature of the wget.

You cannot expect it to work with any other FTP library/software.