Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi Guys i need to create a batch file that can connect to multiple ftp servers to extract a file to one location. Not sure if this is possible but i was thinking in terms of using variables to list the multiple ip address and username and password if required. I havent used variables before in batch files.. any assistance will be great!

you can put all your machine paramaters, eg username, passwords, into a config file (of course you must secure it properly). an example config file
10.10.10.10 user1 password1 file1_to_get 10.10.10.11 user2 password2 file2_to_get
then you can parse it in your script and do the ftp. Here is an example of a Python script (if you can download and install it)import os import ftplib DIR=os.path.join("c:\\","local_directory") os.chdir(DIR) servers={} #store ftp server information for line in open("file"): # get all server information from config file line=line.strip().split() servers.setdefault(line[0],[]) servers[line[0]].extend(line[1:]) def upload(ftp, filename): ftp.storbinary("STOR " + filename, open(filename, "rb"), 1024) def download(ftp, filename): ftp.retrbinary("RETR " + filename, open(filename,"wb").write) for server,params in servers.iteritems(): user=params[0] password=params[1] file_to_get=params[-1] try: ftp = ftplib.FTP(server) ftp.login(user,password) except Exception,e: print e else: ftp.cwd("incoming") #change directory to desired download(ftp,file_to_get)save as myftpscript.py and on command prompt
c:\localdirectory> python myftpscript.py

thanks for your reply, i will try your solution..
i was wondering if it can also be done using a DOS Batch file?
this is what i have come up with so far:
@ftp -i -s:"%~f0"&GOTO:EOF
!Title Connecting...
open server
user
passwordlcd c:\MyLocalDirectory
cd public_html/binary
mget "*.*"disconnect
bye

yes, it can. I , personally don't work with batch files anymore so i will let someone else show you around.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |