FTP Date Format Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • samuraisam

    #1

    FTP Date Format Function

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

    import time
    import datetime

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

  • MC

    #2
    Re: FTP Date Format Function

    Thank.







    --
    @-salutations

    Michel Claveau


    Comment

    • billiejoex

      #3
      Re: FTP Date Format Function

      On 14 Giu, 19:25, samuraisam <samuraib...@gm ail.comwrote:
      FTP LST/LIST/NLST date field formatting function for all those seekers
      out there...
      >
      import time
      import datetime
      >
      def ftpdateformat(v alue):
      """Formats dates from most FTP servers"""
      if ":" in value: # within 6 months
      return datetime.dateti me(
      *time.strptime( # have to guess this calculation
      "%s %s" % (value, datetime.dateti me.now().year),
      "%b %d %H:%M %Y"
      )[0:5]
      ).strftime("%B %d, %Y %H:%M")
      else: # before six months
      return datetime.dateti me(
      *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

      Comment

      • samuraisam

        #4
        Re: FTP Date Format Function

        On Jun 14, 10:53 pm, billiejoex <gne...@gmail.c omwrote:
        On 14 Giu, 19:25, samuraisam <samuraib...@gm ail.comwrote:
        >
        >
        >
        FTP LST/LIST/NLST date field formatting function for all those seekers
        out there...
        >
        import time
        import datetime
        >
        def ftpdateformat(v alue):
        """Formats dates from most FTP servers"""
        if ":" in value: # within 6 months
        return datetime.dateti me(
        *time.strptime( # have to guess this calculation
        "%s %s" % (value, datetime.dateti me.now().year),
        "%b %d %H:%M %Y"
        )[0:5]
        ).strftime("%B %d, %Y %H:%M")
        else: # before six months
        return datetime.dateti me(
        *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. :)

        Comment

        Working...