473,909 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FTP file creation date

Hi all,

I would like to write a script that downloads one file from a ftp
server if the file creation date satisfy a condition.

I can't figure out how to find from a ftp server what is the creation
date of the file (using python).

Any idea?

Thanks for your help!

EuGeNe
Jul 18 '05 #1
5 12479
[ EuGeNe ] wrote:
Hi all,

I would like to write a script that downloads one file from a ftp
server if the file creation date satisfy a condition.

I can't figure out how to find from a ftp server what is the creation
date of the file (using python).

Any idea?

Thanks for your help!

EuGeNe


I don't believe there is anything like .stat methods included
in ftplib. I have always retrieved a directory of the files and
extracted the creation dates from each file manually. Then
acted on them accordingly. You should note that the dates on
most FTP servers are relative to the clock on that server (not
your local clock). If the clock on FTP server is different
from yours, either because it is off or because it is in a
different timezone, you must adjust accordingly.

Larry Bates
Jul 18 '05 #2
[ EuGeNe ] wrote:
Hi all,

I would like to write a script that downloads one file from a ftp
server if the file creation date satisfy a condition.

I can't figure out how to find from a ftp server what is the creation
date of the file (using python).

Any idea?

Thanks for your help!

EuGeNe


Take a look at the ftpmirror.py script that comes in the Tools
directory. It might give you some ideas.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #3
Eugene,

To test for the latest version of a file on the ftpserver,
use the ftplib.sendcmd( ) method with the '4-character'
ftp command for modtime.

#!/usr/bin/python
import ftplib

ftp = ftplib.FTP("ftp .mysite.org")
f.login("anonym ous", "my@email.c om")

# MDTM is an abbreviated '4-char' ftp command
modtime = f.sendcmd("MDTM file.name")

# Strip off the 'reply code'
if modtime[:3] = "213":
modtime = modtime[3:].strip()
Refer to RFC 959 - File Transfer Protocal
http://www.faqs.org/rfcs/rfc959.html

Section4.1 lists the abbreviated ftp commands,
however, 'SIZE' and 'MDTM' are not covered in the RFC
Section4.2.1 covers the Reply Codes.

For examples on using f.sendcmd(), check the module's
source code /usr/lib/python2.2/ftplib.py
Especially, look at the definitions for
def size()
def nlst()
If you're not concerned with portability, you could modify
your systems copy of the library. Add....

def modtime(self, filename):
'''Retrieve the modtime of a file.'''
resp = self.sendcmd('M DTM ' + filename)
if resp[:3] == '213'
s = resp[3:].strip()
return s

Then in your program, you can just say
t = f.modtime("file .name")

Ron Beitel
Jul 18 '05 #4
eu****@boardkul ture.com ([ EuGeNe ]) wrote in message news:<de******* *************** ****@posting.go ogle.com>...
Hi all,

I would like to write a script that downloads one file from a ftp
server if the file creation date satisfy a condition.

I can't figure out how to find from a ftp server what is the creation
date of the file (using python).

Any idea?

Thanks for your help!

EuGeNe


import os, ftplib, time

#============== =============== =============== =============== =============== ====
thisyear = time.localtime( ).tm_year
monthdict={'Jan ': 1,'Feb': 2,'Mar': 3,'Apr': 4,'May': 5,'Jun':
6,'Jul': 7,'Aug': 8,'Sep': 9,'Oct': 10,'Nov': 11,'Dec':12}
#============== =============== =============== =============== =============== ====
def listdir(ftp, path = '.'):
filetimes={}
#-------------------
def callback(line):
ls = line.split()
#print ls -> ['drwxrwxr-x', '2', 'ftpclient', 'k3', '335872',
'Jul', '23', '15:31', 'trash_check']
if len(ls) == 9:
access, x, y, z, size, ls_month, ls_day, ls_union,
ls_filename = ls
tm_mon = monthdict[ls_month]
tm_mday = int(ls_day)
assert len(ls_union) in (4,5)
if len(ls_union) == 5:
assert ls_union[2] == ':'
tm_year = thisyear
tm_hour, tm_min =
int(ls_union[0:2]),int(ls_union[3:5])
elif len(ls_union) == 4:
tm_year = int(ls_union)
tm_hour, tm_min = 0, 0

ftime = time.mktime((tm _year, tm_mon, tm_mday, tm_hour,
tm_min, 0,0,0,-1))
filetimes[ls_filename] = ftime
#------------------
ftp.dir(path, callback)
return filetimes
Jul 18 '05 #5
Ron, and all,

Thanks for your help! It is working :P

Cheers,

EuGeNe
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11334
by: Matt Traxinger | last post by:
Is there a function that determines when a file was created? Like if I wanted to return all the files created in the last month from a directory, is there a way to do that? I've googled and googled but can't find what I'm looking for. Thanks
2
3524
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an idea how to check a creation date it would be appreciated. Thanks dave def delete_old_files (t:\dm\~\users)
0
4672
by: nek | last post by:
Greetings, I am running DB2 WSE V8.1, FP5 on W2K. The problem is not directly related to DB2 but as part of job, I need to manipulate files coming in from all sources. Under a main folder, every subfolder signifies data coming from a different source. The source can further subdivide into more folders.
4
6567
by: wil | last post by:
Dear All, In the linux platform, is there anyway I can in a C program change the file create date? Thanks, wil.
3
6024
by: Steven Blair | last post by:
Hi, I have a trace log file for a system I am writing. If the creation date is older than 14 days, I have to rename that file (File.Move). The next time a trace message is required a new file is created StreamWriter sw = new StreamWriter(path,true); The problem is, the creation date of this new file has the creation date of the previous log file :S and not the present date.
6
14408
by: KoRnDragon | last post by:
I know about getlastmod() but is there one for created date? If not is there some other way of getting the created date of a file?
1
2434
by: avinashpr | last post by:
Hi, How do i fetch the information pertaining to a file like file creation date, modified date.....in c++. small code snippet is hieghly appreceated cheers, avinash
3
3241
by: MrDeej | last post by:
Hello! I am designing an import module in my access database for text files it looks like thisDim GammeltNavn As String Dim NyttNavn As String Dim MaskinNavn As String Dim fsoFileSearch As FileSearch Set fsoFileSearch = Application.FileSearch With fsoFileSearch
2
14667
by: gavin9822623 | last post by:
I need to set a file creation date to "2005/01/01 13:00:00 PM". The date format is (YYYY/MM/DD). Any help or example will be greatly appreciated. Thank you Gavin
0
9879
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11348
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11052
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8099
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7249
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5938
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.