471,334 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 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 5048
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by praba kar | last post: by
12 posts views Thread by Assimalyst | last post: by
11 posts views Thread by shsandeep | last post: by
3 posts views Thread by dave | last post: by
30 posts views Thread by fniles | last post: by
reply views Thread by rosydwin | last post: by

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.