Version 7 of Simple ftp uploader

Updated 2006-04-12 17:17:41

WJG 23/11/05. Having made a photoalbum, PhotoAlbum -A Web Gallery Creation Tool it's time to upload the files to the remote server using ftp.


 package require Tk

 catch { console show }

 # load necessary packages
 package require ftp 
 package require ftp::geturl

 #---------------
 # set appropriate values...
 #---------------
 set host *******
 set user *******
 set pass *******
 set directory /

 #---------------
 # transfer files to server
 #---------------

 proc upload {host user pass dir fileList} {

  set handle [::ftp::Open $host $user $pass]

  # some counters for our feedback string
  set j 1
  set k [llength $fileList]


  foreach i $fileList {
    upload:status "uploading ($j/$k) $i"
    ::ftp::Put $handle $i
    incr j
  }

  ::ftp::Close $handle
 }

 #---------------
 # feedback
 #---------------
 proc upload:status {msg} {
  puts $msg
 }

 #--------------- 
 # create filelist
 #---------------
 set files ""
 foreach i {jpg html css} {
  upload $host $user $pass $directory [glob -nocomplain *.$i]
 }

RLH 2006-Apr-05: Is there a reason Tk is required for this?


Pierre Coueffin 2006-Apr-12: Why does it need the variable "files"?

I'd be tempted to replace:

 if 0 {
  #--------------- 
  # create filelist
  #---------------
  set files ""
  foreach i {jpg html css} {
   upload $host $user $pass $directory [glob -nocomplain *.$i]
  }
 }

with

 if 0 {
  #--------------- 
  # create filelist
  #---------------
  upload $host $user $pass $directory [glob -nocomplain *.jpg *.html *.css]
 }

Unless I'm missing something subtle about how glob works.


Category Internet