ftp again

Sarah Reichelt sarahr at genesearch.com.au
Tue Sep 7 18:22:02 EDT 2004

Hi Rand,

I think you would be much better using callbacks rather than trying to 
block. In my experience, it is not always clear what is being blocked & 
what isn't. Here is what I do, in roughly the same circumstance:

First, make a script local where each line contains the name of one 
file to download.
Make another that contains the FTP path e.g. 
(All the variables starting with "s" are script locals.)
Then call the "doNextDownload" handler ONCE ONLY.

-- loop through downloads
on doNextDownload
   add 1 to sFileCount
   if sFileCount > the number of lines in sDownloadList then
     -- all the downloads are finished, do any tidying up or alerts
     exit doNextDownload
   end if
   put line sFileCount of sDownloadList into tFile
   startDownload tFile
end doNextDownload

-- start downloading file
-- getSaveFolder returns the full path to the folder where the download 
file is to be saved
-- sFtpAddress is a script local that has already been set to include 
the  FTP username, password & path
on startDownload pFileName
   put getSaveFolder() & pFileName into sSaveName
   put sFtpAddress & pFileName into tURL
   put tURL into sFtpURL

   libURLDownloadToFile tURL, sSaveName, downloadDone
end startDownload

-- after download, if successful, process file
-- go on to next one regardless
on downloadDone pURL, pURLStatus
   if pURLstatus contains "error" is false then
     -- do whatever you want with the downloaded file: sSaveName
     -- handle a download failure
   end if
   -- loop to doing the next download
end downloadDone

I am saving the downloaded files to disk. I know you want to show them 
in fields, but I'm sure you can adapt these techniques to suit, either 
by downloading to a temporary file, or downloading into memory in some 

sarahr at genesearch.com.au

On 8 Sep 2004, at 8:06 am, rand valentine wrote:

>  Basically, what I need to do is to download up to 10 files to update 
> an
> informational database -- I have files on a webpage that hold the
> information -- I have no problem uploading any number of files to this
> webpage, but I can't seem to get proper downloading to work. I was 
> using a
> "put" command because it was said to be "blocking," which I assumed to 
> mean
> that the script commands following the "put" command would not be 
> executed
> until the file was fully downloaded. But it appears that this is not 
> the
> case. So here's my question: what is the best way to do this, i.e., to 
> ftp
> download a bunch of files and have them download in serial sequence?

More information about the use-livecode mailing list