home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / tput < prev    next >
Text File  |  2020-01-01  |  2KB  |  52 lines

  1. # Kermit Macro TPUT (Kermit 95 FTP client)
  2. #
  3. # Sends a single file in text mode to an FTP server on an FTP
  4. # connection that must already be open.  Compensates for a bug
  5. # in Kermit 95 2.1.3 that inhibits proper end-of-line conversion
  6. # in text-mode FTP uploads to Unix.  To be used only with Unix-based
  7. # FTP servers.  Usage:
  8. #
  9. #   tput filename
  10. #
  11. # where "filename" is the name of a single text file.
  12. # Creates a temporary file with Unix-style line terminators,
  13. # sends the temporary file in binary mode (under the original file's
  14. # name), then deletes it.
  15. #
  16. # Add this macro definition to your \v(appdata)k95custom.ini
  17. # file and then use "tput" instead of "put" to upload text files
  18. # with FTP from Windows to Unix.
  19. #
  20. # F. da Cruz, Columbia University, 8 April 2004
  21. #
  22. define TPUT {
  23.     local \%c \%w \%i file tmpfile 
  24.     .file := \fcontents(\%1)
  25.     if not = \v(argc) 2 end 1 "Usage: \%0 filename"
  26.     if not exist \m(file) end 1 "?Name of single existing file required"
  27.     fopen /read \%c \m(file)
  28.     if fail end 1
  29.     set flag off
  30.     for \%i 1 1000 1 {
  31.         .tmpfile := \m(file).\frandom(10000)
  32.         if not exist \m(tmpfile) {
  33.             set flag on
  34.             break
  35.         }
  36.     }
  37.     if not flag end 1 "?Can't find unique temp file name"
  38.     fopen /write /binary \%w \m(tmpfile)
  39.     if fail end 1 
  40.     while not \f_eof(\%c) {
  41.         fread /line \%c line
  42.         if fail end 1 "File read error: \m(file)"
  43.         fwrite /string \%w \m(line)\10
  44.         if fail end 1 "File write error: \m(tmpfile)"
  45.     }
  46.     fclose all
  47.     ftp put /binary \m(tmpfile) \m(file)
  48.     if fail end 1 "FTP PUT \m(tmpfile) failed"
  49.     ldelete \m(tmpfile)
  50.     end 0 "TPUT \m(file) OK"
  51. }
  52.