home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / ServiceMail / src / services / ftp.tcl < prev    next >
Encoding:
Text File  |  1993-05-07  |  1.9 KB  |  58 lines

  1. # ftp servicemail gateway
  2. #
  3. # 16-Sept-92 weber@eitech.com
  4. #
  5. # This service retrieves a file from an anonymous ftp site.
  6. #
  7.  
  8. proc ftp {switches envelope inputs} {
  9.   set site [getfield $switches site]
  10. # should this be the requestor instead of the services account?
  11.   set user "[exec whoami]@[exec hostname]"
  12.   set dir  [getfield $switches directory]
  13.   set file [getfield $switches name]
  14.   set mode [getfield $switches mode]
  15.   puts stdout "$site $user $file"
  16.   set fid [open "|ftp -n" w]
  17.   puts $fid "open $site"
  18.   puts $fid "user anonymous $user"
  19.   if {$dir != ""} {puts $fid "cd $dir"}
  20.   if {$mode != ""} {puts $fid "type $mode"}
  21.   puts $fid "get $file $file"
  22.   puts $fid "quit"
  23.   if {[catch "close $fid" ftpout] || ![file exists $file]} {
  24.     setfield response STRING "Sorry, ftp didn't work.\n$ftpout"
  25.     setfield response DESCRIPTION "error return from anon-ftp"
  26.   } {
  27.     setfield response FILE $file
  28.     setfield response DESCRIPTION "the file you requested of anon-ftp"
  29.     setmimetype response
  30.   }
  31.   return [mailout [turnaround $envelope] $response]
  32. }
  33.  
  34. proc setmimetype {objectname} {
  35.     # set up filename as call-by-name
  36.     upvar $objectname object
  37.     set filename [getfield $object FILE]
  38.     case $filename {
  39.     *.ps { setfield object TYPE application; setfield object SUBTYPE postscript }
  40.     *.tex { setfield object TYPE text; setfield object SUBTYPE x-latex }
  41.     *.c { setfield object TYPE application; setfield object SUBTYPE x-c }
  42.     *.sh { setfield object TYPE application; setfield object SUBTYPE x-sh }
  43.     *.tar.Z { setfield object TYPE application
  44.           setfield object SUBTYPE octet-stream
  45.           setfield params name $filename
  46.           setfield params type tar
  47.           setfield params conversions compress
  48.           setfield object PARAMS $params
  49.         }
  50.     *.tar { setfield object TYPE application
  51.           setfield object SUBTYPE octet-stream
  52.           setfield params name $filename
  53.           setfield params type tar
  54.           setfield object PARAMS $params
  55.         }
  56.     }
  57. }
  58.