Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Simple FTP with a batch script

  • 25-02-2009 6: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,212 ✭✭✭✭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,465 ✭✭✭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