FTP example going through a FTP Proxy

jakecjacobson jakecjacobson at gmail.com
Wed Jan 7 14:11:27 EST 2009


On Jan 7, 12:32 pm, jakecjacobson <jakecjacob... at gmail.com> wrote:
> Hi,
>
> I need to write a simple Python script that I can connect to a FTP
> server and download files from the server to my local box.  I am
> required to go through a FTP Proxy and I don't see any examples on how
> to do this.  The FTP proxy doesn't require username or password to
> connect but the FTP server that I am connecting to does.
>
> Any examples on how to do this would be greatly appreciated.  I am
> limited to using Python version 2.4.3 on a Linux box.

This is what I have tried so far,

import urllib

proxies = {'ftp':'ftp://proxy_server:21'}
ftp_server = 'ftp.somecompany.com'
ftp_port='21'
username = 'aaaa'
password = 'secretPW'

ftp_string='ftp://' + username + '@' + password + ftp_server + ':' +
ftp_port


data = urllib.urlopen(ftp_string, proxies=proxies)

data=urllib.urlopen(req).read()

print data

I get the following error:

Traceback (most recent call last):
  File "./ftptest.py", line 22, in ?
    data = urllib.urlopen(ftp_server, proxies=proxies)
  File "/usr/lib/python2.4/urllib.py", line 82, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.4/urllib.py", line 190, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.4/urllib.py", line 470, in open_ftp
    host, path = splithost(url)
  File "/usr/lib/python2.4/urllib.py", line 949, in splithost
    match = _hostprog.match(url)
TypeError: expected string or buffer



More information about the Python-list mailing list