【问题标题】:Append data to file on FTP server in Python在 Python 中将数据附加到 FTP 服务器上的文件
【发布时间】:2015-07-18 04:18:04
【问题描述】:

我每 6 秒将值附加到日志文件中。每 30 秒,我将此日志作为文件传输到 FTP 服务器。但不是传输整个文件,我只想将收集到的数据附加到我服务器上的文件中。我无法弄清楚如何打开服务器文件然后附加值。

到目前为止我的代码:

session = ftplib.FTP(authData[0],authData[1],authData[2])
session.cwd("//"+serverCatalog()+"//") # open server catalog
file = open(fileName(),'rb')

with open(fileName(), 'rb') as f:
     f = f.readlines()
         for line in f:
             collected = line
           
           # In some way open server file, write lines to it
           session.storbinary('STOR ' + fileName(), open(fileName(), 'a'), 1024)
           file.close()
           session.quit()

相反,我是否必须下载打开并附加的服务器文件,然后将其发回?


以上是我的问题,完整的解决方案如下:

session.cwd("//"+serverCatalog()+"//") # open server catalog
localfile = open("logfile.txt",'rb')
session.storbinary('APPE serverfile.txt', localfile)
localfile.close()

【问题讨论】:

    标签: python ftp append ftplib


    【解决方案1】:

    使用APPE 而不是STOR

    来源:http://www.gossamer-threads.com/lists/python/python/22960(链接到 web.archive.org)

    【讨论】:

      猜你喜欢
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多