在 Python 中将数据附加到 FTP 服务器上的文件

编程入门 行业动态 更新时间:2024-10-25 11:19:16
问题描述

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

I'm appending values to a log file every 6th second. Every 30 sec I'm transferring this log to an FTP server as a file. But instead of transfering the whole file, I just want to append the collected data to the file on my server. I haven't been able to figure out how to open the server file and then append the values.

到目前为止我的代码:

session = ftplib.FTP(authData[0],authData[1],authData[2])session.cwd("//"+serverCatalog()+"//") # open server catalogfile = 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()

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

Instead, do I have to download the server file open and append, then send it back?

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

Above was my question, the full solution is below:

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

推荐答案

使用 APPE 而不是 STOR.

来源:www.51sjk/Upload/Articles/1/0/332/332714_20221021101818910.jpg (链接到 web.archive)

  • 0
  • 0
  • 0
  • 0
  • 0

更多推荐

在 Python 中将数据附加到 FTP 服务器上的文件

本文发布于:2023-05-27 09:57:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/285759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   器上   文件   数据   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!