i have error then use ftplib

Stefan Schwarzer sschwarzer at sschwarzer.net
Thu Mar 30 07:35:00 EST 2006


Hello nazarianin,

On 2006-03-30 09:35, 5>=>2 ;5:A59 wrote:
> from ftplib import FTP
> def handleDownload(block):
>     file.write(block)
>     print "."
>
> file = open('1', 'wb')
> ftp = FTP('ftp.utk.ru')
> ftp.set_pasv(1)
> ftp.login()
> ftp.retrlines('LIST')
> [...]

> and have this error message.
>
> Traceback (most recent call last):
>   File "ftp.py", line 10, in ?
>     ftp.retrlines('LIST')
> [...]
> socket.error: (10065, 'No route to host')
>
> Programs that not use Python connect to the server ok.
> Where I do mistake?

Are you sure that you don't need user and password arguments in
.login()? The documentation on ftplib says:

login([user[, passwd[, acct]]])
    Log in as the given user. The passwd and acct parameters are
    optional and default to the empty string. If no user is
    specified, it defaults to 'anonymous'. If user is
    'anonymous', the default passwd is 'anonymous@'. This
    function should be called only once for each instance, after
    a connection has been established; it should not be called at
    all if a host and user were given when the instance was
    created. Most FTP commands are only allowed after the client
    has logged in.

Perhaps the server wasn't satisfied with your credentials and
closed the connection between the .login() and .retrlines()
calls?

Stefan



More information about the Python-list mailing list