FTPlib

Peter A. Schott paschott at no.yahoo.spamm.com
Mon Feb 13 17:58:45 EST 2006


Shouldn't that be:

srcFtp.retrbinary('get ' + file[2:])

or some similar variation?

You're also missing a block telling this where to write the local file.

LocalFile = file.open(file[2:], "wb")
LocalFile.write(srcFtp.retrbinary('get ' + file[2:]) )

(or something similar)

-Pete

"Harlin Seritt" <harlinseritt at yahoo.com> wrote:

> Using ftplib from Python I am trying to get all files in a particular
> directory using ftplib and then send those same files to another ftp
> server. I have tried using commands like 'get *' and 'mget *' with no
> success.
> 
> I am using the following:
> 
> srcFtp = FTP(srcHost)
> srcFtp.login(srcUser, srcPass)
> srcDir = srcFtp.nlst('.')
> for file in srcDir:
>     print file[2:]
>     srcFtp.transfercmd('get '+file[2:])
> 
> I've verified that I do have a connection with the ftp server and the
> files as 'file[2:]' are indeed the file names.
> 
> Anyone know why I get the following error?
> 
> podcast-1.mp3
> Traceback (most recent call last):
>   File "podsync.py", line 17, in ?
>     srcFtp.transfercmd('get '+file[2:])
>   File "C:\Python24\lib\ftplib.py", line 345, in transfercmd
>     return self.ntransfercmd(cmd, rest)[0]
>   File "C:\Python24\lib\ftplib.py", line 327, in ntransfercmd
>     resp = self.sendcmd(cmd)
>   File "C:\Python24\lib\ftplib.py", line 241, in sendcmd
>     return self.getresp()
>   File "C:\Python24\lib\ftplib.py", line 216, in getresp
>     raise error_perm, resp
> ftplib.error_perm: 500 Syntax error, command unrecognized.
> 
> Thanks,
> 
> Harlin Seritt



More information about the Python-list mailing list