开发者

Python ftplib: Overwriting a File doesn't work with STOR

开发者 https://www.devze.com 2022-12-15 06:07 出处:网络
I want to overwrite an existing file \"test.txt\" on my ftp server with this code: from ftplib import FTP

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')
0

精彩评论

暂无评论...
验证码 换一张
取 消