By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

FTPlib

P: n/a
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

Feb 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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>

Feb 13 '06 #2

P: n/a
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" <ha**********@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

Feb 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.