Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Files From FTP Site 1

Status
Not open for further replies.

cghoga

Programmer
Jun 26, 2003
614
US
Please help.

I need a script that will go out to an FTP site and download or copy all of the files onto my local machine.

I tried to do a search of the previous threads but could not find a match.

Any help is greatly appreciated.

Thanks,

Cary
 
Here's a script that should do the trick for you. You'll want to modify lines 11 and 12 so that the FTP path (if the default path when you connect is not the desired directory) and Connection Directory entry to connect to are defined.

proc main
integer iStatus ;Integer to hold $FTPCONNECT results
string sPath ;FTP path to download files from
string sData ;String to hold data from FTP filelist
string sFileSpec ;String to hold path and name of filelist data
string sConnection ;Connection Directory entry we wish to dial

sFileSpec = $PWLOCALPATH ;Set path to Procomm Plus directory
strcat sFileSpec "\FILELIST.TXT" ;Add filename to path

sPath = "" ;Set path that we want to download from
sConnection = "" ;Connection Directory entry to connect to

dial FTP sConnection ;Make connection to FTP site
iStatus = $FTPCONNECT
while (iStatus == 1) ;Wait until connection is established
yield
iStatus = $FTPCONNECT
endwhile
pause 1
switch iStatus
case 3
;Connection attempt failed, perform error handling
endcase
case 2
if not nullstr sPath ;If path on FTP server specified
ftp remote chdir sPath ;Change to that remote directory
endif
ftp remote filelist sFileSpec ;Get list of files from FTP server
while $FTPSTATUS
yield
endwhile
fopen 0 sFileSpec READ TEXT ;Open list of files from FTP server
while not feof 0 ;Loop while file still has data
fgets 0 sData ;Get line of data from file
if not nullstr sData ;If line is not blank
ftp remote copyfile sData ;Copy file to FTP site
while $FTPSTATUS ;Loop while file is being copied
yield
endwhile
endif
endwhile
fclose 0 ;Close file
delfile sFileSpec ;Delete local copy of FTP filelist
endcase
endswitch
disconnect ;Disconnect from FTP server
endproc

aspect@aspectscripting.com
 
Thank you Knob! It works great.

Have a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top