Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007
    Posts
    7

    Exclamation Unanswered: ftp get file with timestamp

    Hi, my knowledge on UNIX scripting is very limited below is my script on getting my file on ftp site but there are bunch of csv files and I only want to get the latest posted on the site. Normally our vendor posted by namefile+date where look like this CML20070904 where
    CML - name of the company
    2007 - year
    09 - month
    04 - date

    please help!


    -----------------------------code --------------------------------
    #!/bin/sh
    # delelete old files
    cd /u001/oracle/camstar/tins/csv_files
    rm *.csv

    HOST='ftp.site.com'
    USER_ASE='ops1'
    PASSWD_ASE='ash'

    ftp -n $HOST << END_SCRIPT
    quote USER $USER_ASE
    quote PASS $PASSWD_ASE
    mget *.csv
    quit
    END_SCRIPT

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    It's difficult to test but would this do it ?
    Do you want the files to keep the dates as part of the name?

    Mike
    Code:
    #!/bin/sh
    
    # delelete old files
    cd /u001/oracle/camstar/tins/csv_files
    rm *.csv
    
    # variables
    HOST='ftp.site.com'
    USER_ASE='ops1'
    PASSWD_ASE='ash'
    TODAY=`date '+%Y%m%d'`
    
    # ftp files
    ftp -n $HOST << END_SCRIPT
       quote USER $USER_ASE
       quote PASS $PASSWD_ASE
       mget *$TODAY.csv
    quit
    
    exit 0

  3. #3
    Join Date
    Sep 2007
    Posts
    7

    Unhappy

    Hi Mike,

    Yes, I want to keept the timestamp together with my filename prefix 'CML'
    I tried your scripts with 'TODAY' as variable but at first when i run it it display the correct format of the variable ex. (CML_20070906) but when it time to do the mget it gets all the file with this kind of format ex.(CML_20070906,CML_20070905,CML_20070904,CML_200 70903) how could i tell to my script only get what is posted today.

    Myra

    # variables
    HOST='ftp.site.com'
    USER_ASE='ops1'
    PASSWD_ASE='ash'
    TODAY=date '+CML_%Y%m%d'`

    # ftp files
    ftp -n $HOST << END_SCRIPT
    quote USER $USER_ASE
    quote PASS $PASSWD_ASE
    mget *$TODAY.csv
    quit

    exit 0

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Myra

    Looking at you're code I think the line
    TODAY=date '+CML_%Y%m%d'`
    should read
    TODAY=`date '+CML_%Y%m%d'`

    so hopefully it's just a typo - sorry for replying late.

    Mike

  5. #5
    Join Date
    Sep 2007
    Posts
    7

    Smile

    Hi Mike,

    Your syntax works! but when I assigned it on a variable and do my mget command it says "file not found".

    What I did is to put it directly on my mget without using variable that look like this....

    mget `date '+ASE_20%y%m%d.csv'`

    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •