473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

FTPlib

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
2 9483
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: python | last post by:
Hi: I want to write a procedure to automatically upload some files for me, but I'm getting stuck. Before I write my own gruesome put() function, I wanted to check if there is an easier way. ...
5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
0
by: Joshua Burvill | last post by:
Hello, I am trying to print something to a print server using the following function but I get errors, does anyone have any pointers? Rgds, Josh Traceback (most recent call last): File...
2
by: Matija Papec | last post by:
I would like to reimplement ftplib "nlst" using ftplib.dir (ftp server doesn't support nlst) so I'm trying to guess how to use ftp callbacks. Any help is appreciated. tia! ============...
2
by: siggy2 | last post by:
Hi, I'm using Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 I've noticed a strange (= not deterministic) behaviour of ftplib.py: sometimes (not always) it fails (after a variable number of...
1
by: Ëåîíîâ Àëåêñåé | last post by:
Hello! I use this code: from ftplib import FTP def handleDownload(block): file.write(block) print "." file = open('1', 'wb') ftp = FTP('ftp.utk.ru')
1
by: Merrigan | last post by:
Hi All, I have written a little script to upload some files to an ftp folder. The problem is as follows : I wrote the script on my windows laptop, and I want to run it from mylinux server....
6
by: half.italian | last post by:
Hi all, I'm using ftplib to transfer large files to remote sites. The process seems to work perfectly with small files, but when the file gets to large ~20GB I begin getting errors that...
1
by: Jon Bowlas | last post by:
Hi All, I've written a little method to connect to an ftpserver which works well, however when I send a file using this ftp connection oddly I _sometimes_ get returned an EOFError from...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.