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 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>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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.
...
|
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...
|
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...
|
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!
============...
|
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...
|
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')
|
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....
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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
| |