FTP status problems. (Again)

Kartic removethis.kartic.krishnamurthy at gmail.com
Sat Sep 17 13:38:36 EDT 2005


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()
> 



More information about the Python-list mailing list