Python: access to ftp like browsers with proxy server

I want to access an ftp server, anonymous, for download only. My company has proxies, and the ftp (21) ports are blocked. I cannot access the ftp server directly.

What I want to do is write code that behaves exactly like browsers do. The idea is that if I can upload files using my browser, there is a way to do this with code.

My code works when I try to access a website outside the company, but still does not work for ftp servers.

proxy = urllib2.ProxyHandler({'https': 'proxy.mycompanhy.com:8080',
                              'http': 'proxy.mycompanhy.com:80',
                              'ftp': 'proxy.mycompanhy.com:21' })
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)

urlAddress = 'https://python.org'
# urlAddress = 'ftp://ftp1.cptec.inpe.br'

conn = urllib2.urlopen(urlAddress)
return_str = conn.read()
print return_str    

python.org, . install_opener, , , -. URL- ftp, ( , ).

, ftp http - . , ftp-. , , , http ftp, html; , - , ftp .

ftp ( URL-) . , urllib2 ftp://... 21.

+4
1

wget. -, . .

import wget
import os
import errno

# setup proxy
os.environ["ftp_proxy"] = "proxy.mycompanhy.com"
os.environ["http_proxy"] = "proxy.mycompanhy.com"
os.environ["https_proxy"] = "proxy.mycompanhy.com"

src = "http://domain.gov/data/fileToDownload.txt"
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)
+2

All Articles