473,604 Members | 2,583 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 12428
[ 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
11317
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
3503
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
4662
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
6526
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
5992
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
14391
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
2421
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
3220
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
14578
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
7997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7929
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
8274
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5882
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
3906
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...
0
3954
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.