|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
File transfer over FTP
I've written the following script to automate my tutorial updates:
Code:
#SolarBear's script of tutorial sending
import ftplib,os
filepath = 'F:\Documents and Settings\David\Mes documents\py\\'
filename = 'python_tutorial_by_SolarBear.pdf'
f = open(filename,'r')
rootr = ftplib.FTP('rootr.com','username','password')
rootr.set_debuglevel(2) #just in case
rootr.cwd('web/solarbear.rootr.com')
try:
rootr.delete(filename)
except: pass
rootr.storbinary('STOR '+ filename,f)
rootr.quit()
f.close()
Connecting and file deletion (is it even necessary ?) work ok, the problem is in the file-sending part : after being 'sent'. I end up with a 3 kb file while it should be around 300 kb. Clearly, only a small portion of the file gets sent. My guess is that the connection closes too fast to leave enough time for the file to be sent... How can I make so the file actually gets sent ?
__________________
Time is the greatest of teachers ; sadly, it kills all of its students. - Hector Berlioz |
|
#2
|
|||
|
|||
|
Well, you set the filepath but you never prepend it to the filename ... looks to me like you should be getting an IOError for the file not existing unless you have a copy in the current directory. Nothing else looks incorrect, the storbinary method should block until it's done, I believe. I think it would also raise an exception if it didn't complete successfully.
|
|
#3
|
||||
|
||||
|
Ok, just a FYI, just in case. After asking around, I finally got to change the following line:
Code:
f = open(filename,'rb') And by opening it as binary, everything goes well and good. |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > File transfer over FTP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|