【问题标题】:Python ftplib: Overwriting a File doesn't work with STORPython ftplib:覆盖文件不适用于 STOR
【发布时间】:2011-01-01 12:15:09
【问题描述】:

我想用以下代码覆盖我的 ftp 服务器上的现有文件“test.txt”:

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

我没有收到任何错误消息,并且文件 test.txt 没有被覆盖(旧的 test.txt 仍在服务器上)。我以为 STOR 会覆盖文件...有人可以帮忙吗? 谢谢!

【问题讨论】:

  • 你确定你有远程文件的写权限吗?
  • STOR 覆盖文件!我检查它并且消息相同(226-文件成功传输)。有@BrianNeal porblem 是对目录的访问权限,您可以查看响应消息。

标签: python ftp file-upload


【解决方案1】:

nvm,是我的错…… 我忘记将当前工作目录更改为 /public_html 还是谢谢!

【讨论】:

    【解决方案2】:

    我认为您需要以写入模式打开文件

    file = open('test.txt', 'w')
    

    【讨论】:

    • 不,那只会破坏 local 副本——OP 想要覆盖 server 副本!
    猜你喜欢
    • 1970-01-01
    • 2020-04-27
    • 2014-07-24
    • 1970-01-01
    • 2016-05-16
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多