V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
piaochen0
V2EX  ›  Python

ftplib 如何获取文件修改时间?

  •  
  •   piaochen0 · 2019-09-04 10:36:03 +08:00 · 2142 次点击
    这是一个创建于 1697 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前是使用的 ftplib 提供的 dir 方法,列出目录下所有的文件
    例如:
    drwx------ 2 0 0 4096 Aug 21 15:57 c

    不过发现返回的列表里,只有月,日,时间。没有年份。 现在有需求要获取完整的时间,麻烦有没有大神知道怎么获取的?

    其实发现 ftplib 的 dir 方法,不同的 FTP 服务器返回的内容都不一样,win 上自带的 ftp 服务器是带了全部时间的。
    不过 linux 上安装的 ftp 服务端返回的不带年份。

    1 条回复    2019-09-04 11:03:35 +08:00
    jinhao7773
        1
    jinhao7773  
       2019-09-04 11:03:35 +08:00
    看 ftplib 的源码里有一个 size 方法,你可以写一个类似的方法使用 MDTM 命令。
    参考 https://en.wikipedia.org/wiki/List_of_FTP_commands
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1312 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 17:39 · PVG 01:39 · LAX 10:39 · JFK 13:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.