python - 使用 Python 了解何时从 FTP 源完全接收到文件

标签 python ftp

我正在使用 Python 开发一个执行以下操作的应用程序:

  • 监视特定目录并监视文件 转移给它。文件传输完成后,运行一些 文件上的外部程序。

我开发这个应用程序的主要问题是知道文件何时完成传输。据我所知,该文件将通过 SFTP 传输到特定目录。 Python 如何知道文件何时完成传输?我知道我可以使用 os.stat(fileName) 方法返回的对象中的 st_size 属性。我需要使用更多工具来实现这些目标吗?

最佳答案

我最终使用了看门狗的组合,一直等到我可以打开文件进行写入

 #If there is no error when trying to read the file, then it has completely loaded
    try:
        with io.FileIO(fileName, "r+") as fileObj:

            '''
            Deal with case where FTP client uses extensions such as ".part" and '.filepart" for part of the incomplete downloaded file.
            To do this, make sure file exists before adding it to list of completedFiles.
            '''
            if(os.path.isfile(fileName)):
                completedFiles.append(fileName)
                print "File=" + fileName + " has completely loaded."
    except IOError as ioe:
        print str(ioe)

关于python - 使用 Python 了解何时从 FTP 源完全接收到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18500496/

相关文章:

python - 为什么 python 列表的 x[False] 和 x[True] 有效?

python - txt 文件中的参数

python - 为什么从包含问号的 rst 文件转换的 html 文件在单击目录时无法在浏览器上显示?

python - 将 re 与变量列表参数一起使用

amazon-ec2 - 使用FTP-WinSCP获得在我的Amazon EC2 Ubuntu服务器上使用文件的权限

linux - 为什么这个 ftp get 命令在我的 shell 脚本中工作但在 cron 中失败

服务器地址为 FQDN 时无法打开 FTP 连接

python - 当一列用管道分隔时,如何读取 pandas 中的 CSV?

linux - 如何将结果 "!find ..."命令重定向到放置 lftp 命令

java - 客户端从服务器读取太多字节?