473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

FTP Date Format Function

FTP LST/LIST/NLST date field formatting function for all those seekers
out there...

import time
import datetime

def ftpdateformat(value):
"""Formats dates from most FTP servers"""
if ":" in value: # within 6 months
return datetime.datetime(
*time.strptime( # have to guess this calculation
"%s %s" % (value, datetime.datetime.now().year),
"%b %d %H:%M %Y"
)[0:5]
).strftime("%B %d, %Y %H:%M")
else: # before six months
return datetime.datetime(
*time.strptime(value, "%b %d %Y")[0:5]
).strftime("%B %d, %Y")

I'm not sure if there is a proper algorithm for deciding on a proper
year within the last 6 months as it isn't given by most FTP servers.
I'd love to amend the function with the correct solution. :)

Jun 14 '07 #1
3 5130
MC
Thank.



--
@-salutations

Michel Claveau
Jun 15 '07 #2
On 14 Giu, 19:25, samuraisam <samuraib...@gmail.comwrote:
FTP LST/LIST/NLST date field formatting function for all those seekers
out there...

import time
import datetime

def ftpdateformat(value):
"""Formats dates from most FTP servers"""
if ":" in value: # within 6 months
return datetime.datetime(
*time.strptime( # have to guess this calculation
"%s %s" % (value, datetime.datetime.now().year),
"%b %d %H:%M %Y"
)[0:5]
).strftime("%B %d, %Y %H:%M")
else: # before six months
return datetime.datetime(
*time.strptime(value, "%b %d %Y")[0:5]
).strftime("%B %d, %Y")

I'm not sure if there is a proper algorithm for deciding on a proper
year within the last 6 months as it isn't given by most FTP servers.
I'd love to amend the function with the correct solution. :)
I didn't well understand your question, anyway...

- FTP got no LST command. What's that?
- NLST should return filenames only: returned output doesn't contain
file sizes, last modification time values or whatever.
- RFC959 gives no specifications about *how* LIST command output
should be formatted. Depending on the type of server you're talking to
you could find unix/"ls -l"-like format outputs, DOS-like ones or
something completely different and your code does not cover all of
them. Take a look at: http://effbot.org/downloads/#ftpparse

Jun 15 '07 #3
On Jun 14, 10:53 pm, billiejoex <gne...@gmail.comwrote:
On 14 Giu, 19:25, samuraisam <samuraib...@gmail.comwrote:
FTP LST/LIST/NLST date field formatting function for all those seekers
out there...
import time
import datetime
def ftpdateformat(value):
"""Formats dates from most FTP servers"""
if ":" in value: # within 6 months
return datetime.datetime(
*time.strptime( # have to guess this calculation
"%s %s" % (value, datetime.datetime.now().year),
"%b %d %H:%M %Y"
)[0:5]
).strftime("%B %d, %Y %H:%M")
else: # before six months
return datetime.datetime(
*time.strptime(value, "%b %d %Y")[0:5]
).strftime("%B %d, %Y")
I'm not sure if there is a proper algorithm for deciding on a proper
year within the last 6 months as it isn't given by most FTP servers.
I'd love to amend the function with the correct solution. :)

I didn't well understand your question, anyway...

- FTP got no LST command. What's that?
- NLST should return filenames only: returned output doesn't contain
file sizes, last modification time values or whatever.
- RFC959 gives no specifications about *how* LIST command output
should be formatted. Depending on the type of server you're talking to
you could find unix/"ls -l"-like format outputs, DOS-like ones or
something completely different and your code does not cover all of
them. Take a look at:http://effbot.org/downloads/#ftpparse
Ah, well if there isn't LST and if NLST doesn't return dates that's
OK, I wasn't sure at the time I authored the post. :)

Jun 15 '07 #4

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

Similar topics

3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
1
by: jt | last post by:
I posted this yesterday, but I am not seeing this out yet: I am having problems with updating a date field in a certain format. The data is stored in an Oracle database. The date is...
5
by: goochey | last post by:
I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this.
8
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
0
by: UBI | last post by:
Vorrei suggerire una funzione completa per la differenza fra due date. (questo è codice freeware, niente di illegale) La funzione seguente permette il calcolo di una differenza precisa tra due...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
11
by: shsandeep | last post by:
I used the following query to retrieve the date in dd-mon-yyyy format. db2 => SELECT RTRIM(CHAR(DAY(COVG_TYP_STRT_DT))) || '-' || RTRIM(MONTHNAME(COVG_TYP_STRT_DT)) || '-' ||...
3
by: dave | last post by:
I need to compute an expiration date based on the number of hours, days, or months purchased. The expiration date needs to be expressed in minutes something like '1260481600'. How can I get the...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
4
by: OzNet | last post by:
I have some functions to calculate the working days in a given period. This includes a table that is queried to calculate the number of public holidays that don’t occur on a weekend. If I test...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.