home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / FTPSAVE.E < prev    next >
Text File  |  1995-10-26  |  5KB  |  122 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. ;  Note:  These are (or should be) brackets:  []
  18. ;
  19. ;                Larry Margolis
  20.  
  21. tryinclude 'MYCNF.E'  -- User can point to FTP.EXE here.  Required if not in path.
  22.  
  23. const
  24. compile if not defined(ftp_pgm)
  25.    ftp_pgm= 'FTP.EXE'                /* location of the FTP.EXE program - in path? */
  26. compile endif
  27.  
  28. defmain
  29.    universal vtemp_path
  30.    parse arg filename machname user pass '/' opts
  31.    mode = ''; cd = ''
  32.    parse value .filename with '[' oldmachname '.' olduser '.' oldcd '] ' oldfn
  33.    parse value .userstring with '' oldpass '' oldmode ''
  34.    do while opts <> ''
  35.       parse value opts with opt rest '/' opts
  36.       opt = upcase(opt)
  37.       if opt='A' | opt='ASC' | opt='ASCII' then
  38.          mode = 'ascii'
  39.       elseif opt='B' | opt='BIN' | opt='BINARY' then
  40.          mode = 'binary'
  41.       elseif opt='CD' then cd = rest
  42.       else
  43.          sayerror 'Unknown option 'opt' ignored.'
  44.       endif
  45.    enddo
  46.    if olduser<> '' then
  47.       if filename = '' then filename = oldfn; endif
  48.       if machname = '' then machname = oldmachname; endif
  49.       if user     = '' then user     = olduser; endif
  50.       if cd       = '' then cd       = oldcd; endif
  51.       if pass     = '' & machname=oldmachname & user=olduser
  52.                        then pass     = oldpass; endif
  53.       if not mode then mode=oldmode; endif
  54.    endif
  55.    if not mode then
  56.       ext = filetype(filename)
  57.       if substr(ext,max(length(ext)-2,1)) = 'BIN' |
  58.          pos(' 'substr(ext,1,3),' BIN RAM ARC EXE LIB DLL COM OBJ SYS FLS ICO TBH IMG GVX ZIP')
  59.       then
  60.          mode = 'binary'
  61.       else
  62.          mode = 'ascii'
  63.       endif
  64.    endif
  65.    if user = '' then
  66.       sayerror 'Required parm missing: FTPSAVE fname mach_name user [pass] [/a | /b] [/cd dir]'
  67.       return
  68.    endif
  69.    if pass = '' then
  70. compile if EVERSION >= '6.01'
  71.       pass = entrybox('Enter password for 'user' on 'machname,
  72.                       '',  -- Buttons
  73.                       '',  -- Entry text
  74.                       '',  -- Cols
  75.                       250,  -- Max len
  76.                       '',  -- Return buffer
  77.                       140) -- ES_UNREADABLE + ES_AUTOSCROLL + ES_MARGIN
  78. compile else
  79.       pass = entrybox('Enter password for 'user' on 'machname)
  80. compile endif
  81.    endif
  82.    if pass = '' then
  83.       sayerror 'No password entered.  Command halted.'
  84.       return
  85.    endif
  86.    wind=substr(ltoa(gethwnd(5),16),1,4)
  87.    cmdfile = vtemp_path'cmds'wind'.ftp'
  88.    tempfile = vtemp_path'SAVE'wind'.FTP'
  89.    'xcom save 'tempfile
  90.    If rc then
  91.       sayerror 'Error 'rc' attempting to save temp file 'tempfile
  92.       return
  93.    endif
  94.    'xcom e /c 'cmdfile
  95.    replaceline 'open 'machname, 1
  96.    insertline 'user 'user pass, 2
  97.    insertline mode, 3
  98.    l = length(vTEMP_PATH)
  99.    insertline 'lcd 'substr(vtemp_path,1,L - (L>3 & substr(vTEMP_PATH,L,1)='\')), 4
  100.    if cd<>'' then
  101.       insertline 'cd 'cd, 5
  102.    endif
  103.    insertline 'put SAVE'wind'.FTP' filename, .last+1
  104.    'xcom save'; src = rc
  105.    'xcom quit'
  106.    if src then sayerror 'Error 'src' saving 'cmdfile'.  Command halted.'; stop; endif
  107.    sayerror 'Attempting to put 'filename' to 'machname cd' in 'mode
  108.    outfile = vtemp_path'outp'wind'.ftp'
  109.    quietshell ftp_pgm '-n -v <'cmdfile '>'outfile -- Need Verbose switch to see error msgs
  110.    ftp_rc = rc
  111.    call erasetemp(cmdfile)
  112.    call erasetemp(tempfile)
  113.    If ftp_rc then
  114.       sayerror 'RC from 'FTP_pgm' =' ftp_rc'; outfile='outfile
  115.       rc = ftp_rc
  116.       return
  117.    endif
  118.    'e /d 'outfile
  119.    sayerror 'Check FTP output for error messages, to see if file was sent.'
  120.    call erasetemp(outfile)
  121.  
  122.