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!

Hi, I am trying to download mult

Status
Not open for further replies.

huskers

Programmer
Jan 29, 2002
75
US
Hi,

I am trying to download multiple files using FTP package in Tcl. I am trying to download all the files which match a pattern like "04022202K*". Could anyone tell me how I can achieve this. Any help would be appreciated. Below is coed snippet with which I am trying to figure out how to acheive this:

proc getFiles {} {

set file "04022002K*"

FTP::Open abcd eeeee aaa
FTP::Cd inc/crp
#Here I need to get all the files matching $file
if {[FTP::Get $file]} {
puts "File found"
} else {
puts "Unable to download file"
}

FTP::Close

}
 
I think what you need to do (since there doesn't appear to be ftp::mget) is to use ftp::directory to read the contents of the remote directory into a list, then use "foreach" on the list and, if the file name matches your condition, ftp::get.

How's that? Bob Rashkin
rrashkin@csc.com
 
Two things come to mind. First, unless explicitly stated otherwise, Tcl is always case-sensitive. So, if you're using the FTP package that's part of Tcllib (the standard Tcl library), the namespace is "ftp", not "FTP", and you should be using calls like ftp::Open and ftp::Cd. For more information on the syntax and usage of the (latest version of the) FTP package, check out
Second, as you've discovered, ftp::Open doesn't handle wildcard expansion. However, the commands for retrieving directory listings, ftp::List and ftp::NList do perform wildcard expansions, and return a list of the files matching the patterns. So, you can then iterate through the list of files returned by one of these commands and do your ftp::Gets in sequence. You can go to the Tcl'ers Wiki ( and check out the page "ftp," for an example of using the FTP package to do a recursive directory listing. That could serve as an example for building your "mget-like" procedure. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top