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!
nvm, it's my fault... I forgot to change the current working directory to /public_html thanks anyway!
I think you need to open the file in write mode
file = open('test.txt', 'w')
精彩评论