getting timestamp of file on remote machine

A forum for general discussion of the Python programming language.

getting timestamp of file on remote machine

Postby zacksolutions » Fri Jan 31, 2014 11:11 pm

Hello,

I am using pysftp to logon to an ftp site. On the remote ftp site, there is a directory. I want to check the timestamp of the files and they are greater than 4 hours from system date/time, then I can assume the files stopped growing and I can move them somewhere else.

I just need help with: "I want to check the timestamp of the files and they are greater than 4 hours from system date/time"

TIA,
zacksolutions
zacksolutions
 
Posts: 12
Joined: Mon Aug 12, 2013 1:23 pm

Re: getting timestamp of file on remote machine

Postby metulburr » Sat Feb 01, 2014 2:19 am

Code: Select all
import os
path = '.'
dicter = {}

for f in os.listdir(path):
    mode = int(os.stat(os.path.join(path, f)).st_ctime)
    dicter[f] = mode

print(dicter)


This example puts the files in the current directory into a dictionary with the files timestamps as the value and the filename as the key. Then you can check the current timestamp against its timestamp for greater value than 4 hours.
http://docs.python.org/2/library/stat.html
Note that on windows its creation time, and on linux/unix its last modification time.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: getting timestamp of file on remote machine

Postby zacksolutions » Sat Feb 01, 2014 2:23 am

Hi metulburr,

Thanks for your reply.

I haven't tested your sample code yet but I wanted to ask if this is going to reference the remote servers directory??
From my painful experience, os.path references my local machine where the script will be run from.

How will your script know I want to pull from the remote ftp server machine and not the local machine where the script is being executed from?

TIA
zacksolutions
zacksolutions
 
Posts: 12
Joined: Mon Aug 12, 2013 1:23 pm

Re: getting timestamp of file on remote machine

Postby metulburr » Sat Feb 01, 2014 2:32 am

I have little experience with running scripts from remote servers. I think others would be best suited to answer that question. I could only assume though, that it would be similar except using the ftp file listing.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: getting timestamp of file on remote machine

Postby stranac » Sat Feb 01, 2014 1:11 pm

You can use the MDTM ftp command to get a file's modified time.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests