Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Simple FTP with a batch script

  • 25-02-2009 06:35AM
    #1
    Registered Users, Registered Users 2 Posts: 2,191 ✭✭✭


    Hey folks,

    I'm trying to put together a batch script though have hit a small issue, if anyone can help me would grately appreciate it.

    Right heres the thing, I basically need to get files from an FTP server. The problem is that the files don't have an extension, they have the same name though the extension is a random number that changes everyday. For example, todays file could be batman.1234 and tomorrows could be batman.9876

    So I need to ask the user for the file extension for that day, simple enough.

    echo Please enter file extension number
    set /p extensionnumber=

    Now heres where I am having the problem, I am connecting to the ftp server using "ftp -s:config.txt" where config.txt holds my ftp parameters. (The good old fashioned way :)

    Eg. config.txt
    Open ftp.myserver
    username
    password
    cd
    lcd
    bin etc etc...
    get batman.

    But how do I pass the user variable that I got earlier into this config.txt, so that when I come to my ftp get command it appends the filename with the variable at the end?.

    eg. get batman.uservariable

    Any ideas?. Or can anyone think of a better way of doing it?. I'm not a programmer though and have very limited programming skills. Cheers in advance :)


Comments

  • Registered Users, Registered Users 2 Posts: 23,202 ✭✭✭✭Tom Dunne


    Feelgood wrote: »
    echo Please enter file extension number
    set /p extensionnumber=

    Now heres where I am having the problem, I am connecting to the ftp server using "ftp -s:config.txt" where config.txt holds my ftp parameters. (The good old fashioned way :)

    Eg. config.txt
    Open ftp.myserver
    username
    password
    cd
    lcd
    bin etc etc...
    get batman.

    But how do I pass the user variable that I got earlier into this config.txt, so that when I come to my ftp get command it appends the filename with the variable at the end?.

    eg. get batman.uservariable

    Any ideas?. Or can anyone think of a better way of doing it?. I'm not a programmer though and have very limited programming skills. Cheers in advance :)

    A quick and dirty way would be to auto-generate the config.txt file each time, substituting the batman.uservariable with batman.%uservariable% The output should be batman.18283 (or what ever). Start off with a TEMPLATE_config.txt which would have the bones of the script:

    Open ftp.myserver
    username
    password
    cd
    lcd
    bin

    Then copy this over to config.txt, append batman.%uservariable% to then end of it via something like ECHO "batman.%uservariable%" >> config.txt

    You then call the new config.txt in the same way : ftp -s:config.txt

    Easy. :)


  • Registered Users, Registered Users 2 Posts: 6,475 ✭✭✭MOH


    Is there only going to be one file on the server each day (i.e. do the old ones get deleted?).

    If so mget batman.* should do it.

    [edit]
    Or what the Rev said, that's a better way.


  • Registered Users, Registered Users 2 Posts: 2,191 ✭✭✭Feelgood


    A quick and dirty way would be to auto-generate the config.txt file each time, substituting the batman.uservariable with batman.%uservariable% The output should be batman.18283 (or what ever). Start off with a TEMPLATE_config.txt which would have the bones of the script:

    Open ftp.myserver
    username
    password
    cd
    lcd
    bin

    Then copy this over to config.txt, append batman.%uservariable% to then end of it via something like ECHO "batman.%uservariable%" >> config.txt

    You then call the new config.txt in the same way : ftp -s:config.txt

    Easy. :)

    Cheers for that my man, much appreciated!. :)


Advertisement