[Tutor] Better way to check *nix remote file age?

Walter Prins wprins at gmail.com
Fri Jun 27 13:41:51 CEST 2014


Hi,

On 26 June 2014 19:40, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
> <snip>
>
>
>> I'd probably rather try Paramiko's SFTPClient and retrieve the file
>
>> modified date directly:
>> http://paramiko-docs.readthedocs.org/en/latest/api/sftp.html#paramiko.sftp_client.SFTPClient
>> (see the SFTPFile.stat() method in particular, which gives you back a
>> stat object containing mtime, the modification datetime IIRC)
>>
>> 2 more (hopefully) useful links if you decide to go this route:
>> http://www.saltycrane.com/blog/2010/02/python-paramiko-notes/
>> http://jessenoller.com/blog/2009/02/05/ssh-programming-with-paramiko-completely-different
>
> Interesting. Question: what is the added value of paramiko compared to using subprocess to use ssh (ie, shell commands)? (Possible answer: it is platform-independent)

Parsing command line output is arguably generally (more) brittle and
prone to breakage than coding to a direct API/library --  Paramiko &
friends give you a proper programming API to code against with
direct/native access to object properties.  A file modification date
and time (for example) from a shell command command is a string that
then must be parsed/interpreted.  This might be subject to locale
format, command/shell settings and who knows what else.  By contrast a
"stat" result is a more well defined entity with unambiguous contents,
completely removing having to guess/parse text.  IMVHO much more
preferable. :)

Walter


More information about the Tutor mailing list