gpt4 book ai didi

python - 如何通过 SFTP 连接下载文件的一部分?

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:49 25 4
gpt4 key购买 nike

所以我有一个Python程序,可以从远程服务器提取访问日志并处理它们。每天都有单独的日志文件。服务器上的文件格式如下:

access.log
access.log-20130715
access.log-20130717

文件“access.log”是当天的日志文件,并且会在一天中使用新数据进行修改。附加时间戳的文件是归档日志文件,并且不会被修改。如果目录中的任何文件被修改,可能是因为 (1) 数据被添加到“access.log”文件中,或者 (2) “access.log”文件正在被归档,并且一个空的文件。文件取代它的位置。每隔一分钟左右,我的程序就会检查目录中任何文件的最新修改时间,如果发生更改,则会拉下“access.log”文件和任何新归档的文件

所有这些目前都运行良好。但是,如果全天将大量数据添加到日志文件中,则一遍又一遍地下载整个文件只是为了获取文件末尾的一些数据,这会在网络上产生大量流量,我会喜欢避免这种情况。有没有办法只下载文件的一部分?如果我已经处理了,比如说 1 GB 的文件,并且突然将另外 500 字节添加到日志文件中,有没有办法只下载最后的 500 字节?

我使用的是Python 3.2,我的本地机器运行的是Windows,远程服务器都运行Linux。我正在使用Chilkat用于建立 SSH 和 SFTP 连接。任何帮助将不胜感激!

最佳答案

调用 ResumeDownloadFileByName。以下是 Chilkat 引用文档中对该方法的描述:

Resumes an SFTP download. The size of the localFilePath is checked and the download begins at the appropriate position in the remoteFilePath. If localFilePath is empty or non-existent, then this method is identical to DownloadFileByName. If the localFilePath is already fully downloaded, then no additional data is downloaded and the method will return True.

参见http://www.chilkatsoft.com/refdoc/pythonCkSFtpRef.html

关于python - 如何通过 SFTP 连接下载文件的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17728470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com