views:

206

answers:

2

I want to overwrite an existing file "test.txt" on my ftp server with this code:

from ftplib import FTP

HOST = 'host.com'
FTP_NAME = 'username'
FTP_PASS = 'password'

ftp = FTP(HOST)
ftp.login(FTP_NAME, FTP_PASS)
file = open('test.txt', 'r')
ftp.storlines('STOR test.txt', file)
ftp.quit()
file.close()

I don't get any error messages and the file test.txt has NOT been overwritten (the old test.txt is still on the server). I thought STOR overwrites files... Can somebody please help? Thanks!

A: 

I think you need to open the file in write mode

file = open('test.txt', 'w')
apt
No, that would just destroy the *local* copy -- the OP wants to overwrite the *server* copy!
Alex Martelli
correct! +1 for that. Thanks
apt
A: 

nvm, it's my fault... I forgot to change the current working directory to /public_html thanks anyway!

creativz