FTP a dynamic file with year and month

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yfguo
    New Member
    • Feb 2008
    • 6

    FTP a dynamic file with year and month

    Do somebody know how to come up with a dynamic file name when ftp it ? I need to download a monthly updated file. The file name appears like datafile_yyyymm .zip where yyyy mean year 2008, and mm mean month 02.
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by yfguo
    Does somebody know how to come up with a dynamic file name when ftp it ? I need to download a monthly updated file. The file name appears like datafile_yyyymm .zip where yyyy mean year 2008, and mm mean month 02.
    Wait, do I understand correctly, you want to download a file once a month, which is called datafile_yyyymm .zip from an FTP-server? And I guess, this should happen automatically? Sounds to me like a batch-script to me... Any experts on that here?

    Greetings,
    Nepomuk

    Comment

    • harshadd
      New Member
      • Dec 2007
      • 180

      #3
      NO matter he wants to upload or download a file.
      Ddefinetly he wants a dynamic file name to be get created which he can create using my 7 lines below. and set as an DOS environment variable.
      copy these three lines in ur .bat or .cmd file. (save as harshad.bat)
      note:-
      Date command is passed in this bat file to get current system date.
      It requires an input from user on console.which is redirected using "<" to an empty file named "enter"

      bat/cmd file is as below: harshad.bat

      @ECHO OFF
      for /f "usebackq delims=/ tokens=3" %%x IN (`date`) do set YYYY=%%x
      for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set MM=%%x
      SET FILENAME=DATAFI LE_
      FOR %%Y IN (%YYYY%) DO SET FILENAME=%FILEN AME%%%Y
      FOR %%Z IN (%MM%) DO SET FILENAME=%FILEN AME%%%Z.ZIP
      echo %FILENAME%

      to create an emptyfile named "enter" do this on DOS prompt
      copy con enter
      then press enter key one time to store Carrage Return in the file named "enter"
      then press F6 to save file.

      when u execute ececute it like this
      harshad <enter
      and u will have an envirnment variable filename set to your required filename
      type SET and check this
      tested on XP PRO SP 2

      I BET I AM THE MOST POWERFULL MSDOS USER IN ENTIRE MUMBAI ANY ONE WANTs TO CHALLANGE THIS STATEMENT?

      HARSHAD.

      Comment

      • yfguo
        New Member
        • Feb 2008
        • 6

        #4
        thank your reply. I think that works.

        Here another question rises due my further investigation on not only downloading a file through ftp, but also through http. do you have any idea how to use NT commands to download a file from a web like http://www.mydomain.co m/data/datafile.zip ?

        Thanks in advance.

        Comment

        • harshadd
          New Member
          • Dec 2007
          • 180

          #5
          Originally posted by yfguo
          thank your reply. I think that works.

          Here another question rises due my further investigation on not only downloading a file through ftp, but also through http. do you have any idea how to use NT commands to download a file from a web like http://www.mydomain.co m/data/datafile.zip ?

          Thanks in advance.
          If you know the perfect URL of the file , asuming that the only file name will change daily. you can directly put this URL on browser to get the file d/loaded.
          optionally u can make VB/VBS script for this... HND

          Comment

          • Nepomuk
            Recognized Expert Specialist
            • Aug 2007
            • 3111

            #6
            Originally posted by yfguo
            thank your reply. I think that works.

            Here another question rises due my further investigation on not only downloading a file through ftp, but also through http. do you have any idea how to use NT commands to download a file from a web like http://www.mydomain.co m/data/datafile.zip ?

            Thanks in advance.
            To download a file from command line, you can use a program like wget, which originally comes from the *nix area, but was ported to Windows.

            You just have to use the command
            Code:
            wget "http://www.mydomain.com/data/datafile.zip"
            to download it.
            By the way, wget supports both ftp and http downloads.

            Greetings,
            Nepomuk

            Comment

            • shanaf
              New Member
              • Mar 2008
              • 1

              #7
              Originally posted by harshadd
              NO matter he wants to upload or download a file.
              Ddefinetly he wants a dynamic file name to be get created which he can create using my 7 lines below. and set as an DOS environment variable.
              copy these three lines in ur .bat or .cmd file. (save as harshad.bat)
              note:-
              Date command is passed in this bat file to get current system date.
              It requires an input from user on console.which is redirected using "<" to an empty file named "enter"

              bat/cmd file is as below: harshad.bat

              @ECHO OFF
              for /f "usebackq delims=/ tokens=3" %%x IN (`date`) do set YYYY=%%x
              for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set MM=%%x
              SET FILENAME=DATAFI LE_
              FOR %%Y IN (%YYYY%) DO SET FILENAME=%FILEN AME%%%Y
              FOR %%Z IN (%MM%) DO SET FILENAME=%FILEN AME%%%Z.ZIP
              echo %FILENAME%

              to create an emptyfile named "enter" do this on DOS prompt
              copy con enter
              then press enter key one time to store Carrage Return in the file named "enter"
              then press F6 to save file.

              when u execute ececute it like this
              harshad <enter
              and u will have an envirnment variable filename set to your required filename
              type SET and check this
              tested on XP PRO SP 2

              I BET I AM THE MOST POWERFULL MSDOS USER IN ENTIRE MUMBAI ANY ONE WANTs TO CHALLANGE THIS STATEMENT?

              HARSHAD.

              Thanx harshadd, but can you show me how to fetch a dynamic file name like "datafile_ddmmy y.csv" from an ftp location like "ftp://location/folder/datafile_ddmmyy .csv" and save it as "datafile.c sv" in the location of the bat script?

              Comment

              • harshadd
                New Member
                • Dec 2007
                • 180

                #8
                Originally posted by shanaf
                Thanx harshadd, but can you show me how to fetch a dynamic file name like "datafile_ddmmy y.csv" from an ftp location like "ftp://location/folder/datafile_ddmmyy .csv" and save it as "datafile.c sv" in the location of the bat script?
                Date command from DOS returns o/p like this
                C:\>date
                The current date is: 31/03/2008
                Enter the new date: (dd-mm-yy)
                here Year is in YYYY format.
                You required in YY format.. its posible but not easy task to get it converted into YY.
                Please feedle with FOR command and try to get only 2 digit year as output

                FOR /f "usebackq delims=/ tokens=3" %x IN (`date`) do echo %x
                Also getting Date is too NOT simple as above commands can give you year(YYYY)
                and Month (MM) by changing tokens=2
                But tokens=1 do not give date in (DD) form


                wait... let me try........

                Comment

                • harshadd
                  New Member
                  • Dec 2007
                  • 180

                  #9
                  To get filename dinamically as datafile_ddmmyy .csv use the below .BAT file.
                  note you have to have your regional setting for this bat file to work properly as
                  CUSTOM date "/dd/MM/yyy" instead of "dd/MM/yyyy" .
                  Note that MM is in caps and and an extra "/" is required to work with this bat file.
                  This is only because I can not resolve Date part of date if date is not starting with "/" Month and year can be resolved as u seen earlier....
                  Regards HArshad.

                  ///start harshad.bat
                  @ECHO OFF
                  for /f "usebackq delims=/ tokens=3" %%x IN (`date`) do set YYYY=%%x
                  for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set MM=%%x
                  for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set DD=%%x

                  SET FILENAME=DATAFI LE_
                  FOR %%Y IN (%YYYY%) DO SET FILENAME=%FILEN AME%%%Y
                  FOR %%Z IN (%MM%) DO SET FILENAME=%FILEN AME%%%Z
                  FOR %%X IN (%DD%) DO SET FILENAME=%FILEN AME%%%X.csv

                  echo %FILENAME%
                  //end harshad.bat

                  I am working on this to happend without changing regional settings or to change it and reset back onthe fly.
                  Regards
                  Harshad

                  Comment

                  Working...