Harlin Seritt 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.
ftplib works with FTP protocol commands, not ftp client commands (such as get and mget). to read data from a remote server, you can use something like: dst = open(localfile, "wb") srcFtp.retrbinary("RETR " + file[2:], dst.write) dst.close() for more examples, see http://effbot.org/librarybook/ftplib.htm for an extensive description of FTP-as-deployed, see daniel bernstein's site: http://cr.yp.to/ftp.html hope this helps! </F> -- http://mail.python.org/mailman/listinfo/python-list