#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    FTP server as variable


    I am using two files. The first file is a bat file that change the directory, creates a new sub directory if it does not exist and starts my ftp session. The second file opens the ftp session, changes the directory on the remote server, changes the directory on the local machine, and gets all file in the remote directory. The problem is I have more than 30 servers I need to receive from. I need if possible for the mkdir in the first file to be a variable as well as open and lcd in the second file. The below codes works as is and I could just keep adding to it for the other servers, but more servers will be added and I would rather just add them as a variable if it can be done. Any help would be appreciated.

    start ftp download script.bat
    Code:
    cd C:\Documents and Settings\User\My Documents\backup files
    
    mkdir 11.11.11.11
    
    ftp -s:ftp_download_script.scr
    ftp_download_script.scr
    Code:
    prompt
    
    open 11.11.11.11
    Admin
    Admin
    cd /data/Config
    lcd 11.11.11.11
    mget *.*
    lcd ..
    close
    
    quit
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    You can use command arguments like
    Code:
    script.bat 11.11.11.11
    The files would (probably) look like
    Code:
    cd /d C:\Documents and Settings\User\My Documents\backup files
    
    mkdir %1
    cd %1
    
    ftp -n -s:../ftp_download_script.scr %1
    Code:
    prompt
    
    user
    Admin
    Admin
    cd /data/Config
    mget *.*
    close
    
    quit
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    5
    Rep Power
    0
    I left a little information out. This will be a scheduled task that downloads these files from each server once a week. I believe I will need an if statement that will look at another file for each IP address until it reaches the end.
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    You can do that in a batch file: read lines from a file and execute a command.

    The command is like
    Code:
    FOR /F %i IN (servers.txt) DO script.bat %i
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    5
    Rep Power
    0
    I think I almost have this figured out. The below code works as I expect if I paste it in a command line. Even though I get the following error: "| was unexpected at this time. The process tried to write to a nonexistent pipe." I have read that to run this code in a batch file I should change %i to %%i, but when I do that the loop never stops and it does not do any of the processing. What am I doing wrong?

    start_ftp_download_script.bat
    Code:
    cd /d C:\Documents and Settings\User\My Documents\backup files
    FOR /F %i in (servers.txt) DO ( start_ftp_download_script.bat %i | mkdir %i && cd %i && ftp -s:../ftp_download_script.scr %i && cd..)
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    Move all the commands into the .bat. More or less like what I posted.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    5
    Rep Power
    0
    The code I posted is my bat file, but it does not process when I run the bat file.
  14. #8
  15. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    The file calls itself. Over and over again. So it will never stop until it crashes.

    Then there's two batch files: one to read addresses from the text file and one to execute the FTP script.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    5
    Rep Power
    0
    That was my problem. I thought the file needed to call itself in order to re-execute. Thanks for all of your help.

IMN logo majestic logo threadwatch logo seochat tools logo