我有一个代码可以从SFTP服务器下载5天或更旧的文件。但是,我不想下载文件,而是要将5天前的文件名存储到列表中。请帮我修改代码。预先感谢
我现在正在使用的代码(基于Download files from SFTP server that are older than 5 days using Python)
+----+------+--------------+-------+
| id | name | parentStudio | level |
+----+------+--------------+-------+
| 1 | B | 0 | 0 |
+----+------+--------------+-------+
| 0 | A | null | 1 |
+----+------+--------------+-------+
| 6 | G | null | 2 |
+----+------+--------------+-------+
| 3 | D | 2 | 0 |
+----+------+--------------+-------+
| 2 | C | null | 1 |
+----+------+--------------+-------+
| 4 | E | null | 0 |
+----+------+--------------+-------+
答案 0 :(得分:1)
我没有使用sftp.get
下载文件,而是将它们的路径添加到列表中,并在最后将其返回
import time
def get_r_portable(sftp, remotedir):
result = []
for entry in sftp.listdir_attr(remotedir):
remotepath = remotedir + "/" + entry.filename
mode = entry.st_mode
if S_ISDIR(mode):
result += get_r_portable(sftp, remotepath)
elif S_ISREG(mode):
if (time.time() - entry.st_mtime) // (24 * 3600) >= 5:
result.append(entry.filename)
return result