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

FTP status problems. (Again)

P: n/a
Hello, I have posted before about trying to find the status of an FTP
uplaod but couldn't get anything to work. After some more searching I
found
http://groups.google.com/group/comp....917c906cdc04d4
but it does not seem to work because it just uploads the file and does
not print a . onto the screen. HEre is the code I have when I'm using
the code from that link.
import ftplib
import os
class dot_FTP(ftplib.FTP):
def storbinary(self, cmd, fp, blocksize=8192):
self.voidcmd('TYPE I')
conn = self.transfercmd(cmd)
while 1:
buf = fp.read(blocksize)
if not buf: break
conn.send(buf)
sys.stdout.write('.')
sys.stdout.flush()
conn.close()
return self.voidresp()
ftp = ftplib.FTP("FTPADDRESS")
ftp.login("user","pass")
file = "/file"
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
ftp.quit()
Does anyone know why this is not working? IS there any other way to
find out when a chunc has been sent or the bytes uploaded of a file?
Thanks.

Sep 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Fri, 2005-09-16 at 19:27 -0700, Nainto wrote:
Hello, I have posted before about trying to find the status of an FTP
uplaod but couldn't get anything to work. After some more searching I
found
http://groups.google.com/group/comp....917c906cdc04d4
but it does not seem to work because it just uploads the file and does
not print a . onto the screen. HEre is the code I have when I'm using
the code from that link.
import ftplib
import os
class dot_FTP(ftplib.FTP):
def storbinary(self, cmd, fp, blocksize=8192):
self.voidcmd('TYPE I')
conn = self.transfercmd(cmd)
while 1:
buf = fp.read(blocksize)
if not buf: break
conn.send(buf)
sys.stdout.write('.')
sys.stdout.flush()
conn.close()
return self.voidresp()
ftp = ftplib.FTP("FTPADDRESS")
ftp.login("user","pass")
file = "/file"
ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
ftp.quit()
Does anyone know why this is not working? IS there any other way to
find out when a chunc has been sent or the bytes uploaded of a file?
Thanks.


.... and I haven't tried this myself, but you should be able to subclass
the builtin file object and prepare your own read() method. Something
like

class ProgressFile(file):

def read(self, size = None):
print '.',

if size is not None:
return file.read(self, size)
else:
return file.read()

May need some tweaking.. then store the file as

ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)

Give it a try..

-m

Sep 17 '05 #2

P: n/a
On Sat, 2005-09-17 at 04:42 +0000, marduk wrote:

... and I haven't tried this myself, but you should be able to subclass
the builtin file object and prepare your own read() method. Something
like

class ProgressFile(file):

def read(self, size = None):
print '.',

if size is not None:
return file.read(self, size)
else:
return file.read()

May need some tweaking.. then store the file as

ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)

Give it a try..

-m


I corrected some errors and made some modifications to my previous post:

class ProgressFile(file):
def read(self, size = None):
from sys import stdout

if size is not None:
buff = file.read(self, size)
if buff:
stdout.write('.')
else:
stdout.write('\n')
return buff
else:
buff = ''
while True:
new_str = file.read(self, 1024)
stdout.write('.')
if new_str:
buff = buff + new_str
else:
stdout.write('\n')
break
return buff
if __name__ == '__main__':
import sys

fname = sys.argv[1]
f = ProgressFile(fname)
f.read()
Sep 17 '05 #3

P: n/a
Thanks, I'll give this a try. This will print a period right?

Sep 17 '05 #4

P: n/a
When I execute the folllowing code with all of the address, username,
and passwords filled out I gt an error saying:
"/Library/Frameworks/Python.framework/Versions/2.4/Resources/Python.app/Contents/MacOS/Python"
"/Users/zacim/Documents/FireUpFTP/foramttedthing" ; exit
Traceback (most recent call last):
File "/Users/zacim/Documents/FireUpFTP/foramttedthing", line 26, in ?
fname = sys.argv[1]
IndexError: list index out of range
logout
[Process completed]

This is the code:

import ftplib
class ProgressFile(file):
def read(self, size = None):
from sys import stdout

if size is not None:
buff = file.read(self, size)
if buff:
stdout.write('.')
else:
stdout.write('\n')
return buff
else:
buff = ''
while True:
new_str = file.read(self, 1024)
stdout.write('.')
if new_str:
buff = buff + new_str
else:
stdout.write('\n')
break
return buff
if __name__ == '__main__':
import sys
fname = sys.argv[1]
f = ProgressFile(fname)
f.read()

ftp = ftplib.FTP("ftp.sadpanda.cjb.cc")
ftp.login("sadpanda","s4dp4nd4b1g")
file = "/FrenchBrochure.pages.zip.gz"
ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)
ftp.quit()

Sep 17 '05 #5

P: n/a
That is because you have just taken marduk's program and included your
ftp code... please see what he has done in the if __name__ == '__main__'
part.

He expects the file name as an commandline argument (sys.argv[1]) and
since you just copied his code, you are invoking the script *without*
the argument. This is what the exception means when it says "list index
out of range".

To make ProgressFile class work for you with the filename you have
hardcoded... make the following modification to the "if __name ==" part:

if __name__ == '__main__':
ftp = ftplib.FTP("ftp.sadpanda.cjb.cc")
ftp.login("sadpanda","s4dp4nd4b1g")
file = "/FrenchBrochure.pages.zip.gz"
ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)
ftp.quit()

Thanks,
-Kartic

The Great 'Nainto' uttered these words on 9/17/2005 9:08 AM:
When I execute the folllowing code with all of the address, username,
and passwords filled out I gt an error saying:
"/Library/Frameworks/Python.framework/Versions/2.4/Resources/Python.app/Contents/MacOS/Python"
"/Users/zacim/Documents/FireUpFTP/foramttedthing" ; exit
Traceback (most recent call last):
File "/Users/zacim/Documents/FireUpFTP/foramttedthing", line 26, in ?
fname = sys.argv[1]
IndexError: list index out of range
logout
[Process completed]

This is the code:

import ftplib
class ProgressFile(file):
def read(self, size = None):
from sys import stdout

if size is not None:
buff = file.read(self, size)
if buff:
stdout.write('.')
else:
stdout.write('\n')
return buff
else:
buff = ''
while True:
new_str = file.read(self, 1024)
stdout.write('.')
if new_str:
buff = buff + new_str
else:
stdout.write('\n')
break
return buff
if __name__ == '__main__':
import sys
fname = sys.argv[1]
f = ProgressFile(fname)
f.read()

ftp = ftplib.FTP("ftp.sadpanda.cjb.cc")
ftp.login("sadpanda","s4dp4nd4b1g")
file = "/FrenchBrochure.pages.zip.gz"
ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)
ftp.quit()

Sep 17 '05 #6

P: n/a
I'm really sorry that I keep having problems with this. :-( Now I get:
TypeError: Error when calling the metaclass bases[] str() takes at most
1 arguement (3 given)

and the Traceback is:

file "formattedthing", line 2, in '?'
classProgressFile(file)

With the following code:

import ftplib
class ProgressFile(file):
def read(self, size = None):
from sys import stdout
if size is not None:
buff = file.read(self, size)
if buff:
stdout.write('.')
else:
stdout.write('\n')
return buff
else:
buff = ''
while True:
new_str = file.read(self, 1024)
stdout.write('.')
if new_str:
buff = buff + new_str
else:
stdout.write('\n')
break
return buff
if __name__ == '__main__':
ftp = ftplib.FTP("ftp.sadpanda.cjb.cc")
ftp.login("sadpanda","PASSWORDEDITEDOUT")
file = "/FrenchBrochure.pages.zip"
ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)
ftp.quit()

Thanks so muchy for help guys. :-)

Sep 17 '05 #7

P: n/a
Hello,
file = "/FrenchBrochure.pages.zip"
ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)


You are using file = "/FrenchBrochure.pages.zip" (sorry I did not notice
earlier).

You can not use file as variable name like you have, as it represents a
file object in python.

Please change your variable name from file to filename.

Thanks.
Sep 17 '05 #8

P: n/a
Unfortunatly I stiill get the same error. :-(
Here is the code:
import ftplib
class ProgressFile(file):
def read(self, size = None):
from sys import stdout
if size is not None:
buff = file.read(self, size)
if buff:
stdout.write('.')
else:
stdout.write('\n')
return buff
else:
buff = ''
while True:
new_str = file.read(self, 1024)
stdout.write('.')
if new_str:
buff = buff + new_str
else:
stdout.write('\n')
break
return buff
if __name__ == '__main__':
ftp = ftplib.FTP("ftp.sadpanda.cjb.cc")
ftp.login("sadpanda","PASSWORDEDITIEDOUT")
filename = "/FrenchBrochure.pages.zip"
ftp.storbinary("STOR " + filename, ProgressFile(filename, "rb"), 1024)

ftp.quit()
Thanks again.

Sep 17 '05 #9

P: n/a
> Unfortunatly I stiill get the same error. :-(

The same "metaclass bases[]" error??
Here is the code:
import ftplib -snip- if __name__ == '__main__':
ftp = ftplib.FTP("ftp.sadpanda.cjb.cc")
ftp.login("sadpanda","PASSWORDEDITIEDOUT")
filename = "/FrenchBrochure.pages.zip"
ftp.storbinary("STOR " + filename, ProgressFile(filename, "rb"), 1024)

ftp.quit()

Your code works for me.. I just made one minor change.

I gave a different target name:

filename = "/FrenchBrochure.pages.zip"
target = "FrenchBrochure.pages.zip"
ftp.storbinary("STOR " + target, ProgressFile(filename, "rb"), 1024)

Thanks,
-Kartic
Sep 17 '05 #10

P: n/a
It works! Thanks so much for your help!

Sep 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.