监控远程FTP目录
- 作者: yl
- 来源: 51数据库
- 2022-10-21
问题描述
我只能通过 FTP 访问远程服务器上的目录,并且希望在新文件出现在目录中时立即获取它们的内容.
I only have FTP access to a directory on a remote server and would like to get the contents of new files as soon as they appear in the directory.
有没有类似 FAM for Python 的东西可以让我通过 FTP 监控新文件?
Is there any thing like FAM for Python that lets me monitor for new files over FTP?
推荐答案
如果轮询服务器是一个选项:
If polling the server is an option:
from ftplib import FTP
from time import sleep
ftp = FTP('localhost')
ftp.login()
def changemon(dir='./'):
ls_prev = set()
while True:
ls = set(ftp.nlst(dir))
add, rem = ls-ls_prev, ls_prev-ls
if add or rem: yield add, rem
ls_prev = ls
sleep(5)
for add, rem in changemon():
print('
'.join('+ %s' % i for i in add))
print('
'.join('- %s' % i for i in remove))
ftp.quit()
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
