Computing.Net > Forums > Programming > Multiple FTP Batch File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Multiple FTP Batch File

Reply to Message Icon

Name: IT
Date: May 27, 2009 at 18:07:26 Pacific
OS: Windows
Subcategory: Batch
Comment:

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!



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: May 27, 2009 at 19:04:14 Pacific
Reply:

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


0

Response Number 2
Name: IT
Date: May 27, 2009 at 21:03:37 Pacific
Reply:

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
password

lcd c:\MyLocalDirectory
cd public_html/

binary
mget "*.*"

disconnect
bye


0

Response Number 3
Name: ghostdog
Date: May 28, 2009 at 01:01:26 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Multiple FTP Batch File

FTP batch file www.computing.net/answers/programming/ftp-batch-file/9027.html

FTP Batch File www.computing.net/answers/programming/ftp-batch-file/16866.html

Batch file for Internet Explorer www.computing.net/answers/programming/batch-file-for-internet-explorer/18946.html