home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / epmsmp / ftpsave.e < prev    next >
Text File  |  1992-08-26  |  4KB  |  110 lines

  1. ;  FTPSAVE command, for saving a file via FTP.  Syntax is:
  2. ;     FTPLOAD file_name machine_name user [pass] [/a | /b] [/cd dir]
  3. ;  /ASCII and /BINARY set the mode for the file transfer; /CD is useful
  4. ;  when going to VM where CD is required to access a new disk.  If the
  5. ;  password is omitted, it will be prompted for * (so it's not available
  6. ;  in the command stack for others to see).  If any other arguments are
  7. ;  omitted, and the file was loaded via FTPLOAD, the corresponding parameters
  8. ;  will be used from the FTPLOAD command.  Examples:
  9. ;     FTPSAVE /tcpip/etc/sendmail.cf lamail myuserid mypass
  10. ;     FTPSAVE ftpload.ebin VM_host myuserid /cd EOS2.194
  11. ;
  12. ;  This works with the FTP program from IBM's OS/2 TCP/IP product; it has not
  13. ;  been tried with any other versions.
  14. ;
  15. ;  * Note:  The password prompting only works for EPM.
  16. ;
  17. ;                Larry Margolis
  18.  
  19. tryinclude 'MYCNF.E'  -- User can point to FTP.EXE here.  Required if not in path.
  20.  
  21. const
  22. compile if not defined(ftp_pgm)
  23.    ftp_pgm= 'FTP.EXE'                /* location of the FTP.EXE program - in path? */
  24. compile endif
  25.  
  26. defmain
  27.    universal vtemp_path
  28.    parse arg filename machname user pass '/' opts
  29.    mode = ''; cd = ''
  30.    parse value .filename with '[' oldmachname '.' olduser '.' oldcd '] ' oldfn
  31.    parse value .userstring with '' oldpass '' oldmode ''
  32.    do while opts <> ''
  33.       parse value opts with opt rest '/' opts
  34.       opt = upcase(opt)
  35.       if opt='A' | opt='ASC' | opt='ASCII' then
  36.          mode = 'ascii'
  37.       elseif opt='B' | opt='BIN' | opt='BINARY' then
  38.          mode = 'binary'
  39.       elseif opt='CD' then cd = rest
  40.       else
  41.          sayerror 'Unknown option 'opt' ignored.'
  42.       endif
  43.    enddo
  44.    if olduser<> '' then
  45.       if filename = '' then filename = oldfn; endif
  46.       if machname = '' then machname = oldmachname; endif
  47.       if user     = '' then user     = olduser; endif
  48.       if cd       = '' then cd       = oldcd; endif
  49.       if pass     = '' & machname=oldmachname & user=olduser
  50.                        then pass     = oldpass; endif
  51.       if not mode then mode=oldmode; endif
  52.    endif
  53.    if not mode then
  54.       ext = filetype(filename)
  55.       if substr(ext,max(length(ext)-2,1)) = 'BIN' |
  56.          pos(' 'substr(ext,1,3),' BIN RAM ARC EXE LIB DLL COM OBJ SYS FLS ICO TBH IMG GVX ZIP')
  57.       then
  58.          mode = 'binary'
  59.       else
  60.          mode = 'ascii'
  61.       endif
  62.    endif
  63.    if user = '' then
  64.       sayerror 'Required parm missing: FTPSAVE fname mach_name user [pass] [/a | /b] [/cd dir]'
  65.       return
  66.    endif
  67.    if pass = '' then
  68.       pass = entrybox('Enter password for 'user' on 'machname)
  69.    endif
  70.    if pass = '' then
  71.       sayerror 'No password entered.  Command halted.'
  72.       return
  73.    endif
  74.    wind=substr(ltoa(gethwnd(5),16),1,4)
  75.    cmdfile = vtemp_path'cmds'wind'.ftp'
  76.    tempfile = vtemp_path'SAVE'wind'.FTP'
  77.    'xcom save 'tempfile
  78.    If rc then
  79.       sayerror 'Error 'rc' attempting to save temp file 'tempfile
  80.       return
  81.    endif
  82.    'xcom e /c 'cmdfile
  83.    replaceline 'open 'machname, 1
  84.    insertline 'user 'user pass, 2
  85.    insertline mode, 3
  86.    l = length(vTEMP_PATH)
  87.    insertline 'lcd 'substr(vtemp_path,1,L - (L>3 & substr(vTEMP_PATH,L,1)='\')), 4
  88.    if cd<>'' then
  89.       insertline 'cd 'cd, 5
  90.    endif
  91.    insertline 'put SAVE'wind'.FTP' filename, .last+1
  92.    'xcom save'; src = rc
  93.    'xcom quit'
  94.    if src then sayerror 'Error 'src' saving 'cmdfile'.  Command halted.'; stop; endif
  95.    sayerror 'Attempting to put 'filename' to 'machname cd' in 'mode
  96.    outfile = vtemp_path'outp'wind'.ftp'
  97.    quietshell ftp_pgm '-n -v <'cmdfile '>'outfile -- Need Verbose switch to see error msgs
  98.    ftp_rc = rc
  99.    call erasetemp(cmdfile)
  100.    call erasetemp(tempfile)
  101.    If ftp_rc then
  102.       sayerror 'RC from 'FTP_pgm' =' ftp_rc'; outfile='outfile
  103.       rc = ftp_rc
  104.       return
  105.    endif
  106.    'e /d 'outfile
  107.    sayerror 'Check FTP output for error messages, to see if file was sent.'
  108.    call erasetemp(outfile)
  109.  
  110.