home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / ftpfid17.zip / FTPSEND.CMD < prev    next >
OS/2 REXX Batch file  |  1996-09-14  |  27KB  |  829 lines

  1. /* FTPsend.CMD - rexx script to get FidoNet mail via FTP */
  2.  
  3. /*------------------------------------------------------------------
  4.  * Version 1.7send by Jerry Gause 1:3651/9
  5.  * This version simply sends *.* from "ftpout" for
  6.  * MFLO users.
  7.  * Many thanks go to Donnie Benners for the original base code
  8.  * and of course to Patrick J. Mueller & Cliff Nadler for RxFtp.
  9.  * Change global variables below to suit your system.
  10.  * Change lines marked with "CFP!!!" to suit your provider.
  11.  * Important!!!!!!!!!!!!!
  12.  * Dlls needed for this script are: RxFtp, Rexxutil and Rexxlib.
  13.  * Rxftp is included in it's own archive.
  14.  * If using OS/2 2.X be sure to use the Rxftp32.Dll renamed
  15.  * to Rxftp.dll.
  16.  * Rexxlib was not included because it's shareware.
  17.  * It is only needed for the "hangup" routine.
  18.  * You can freq it from me as Rexxlb.Zip.
  19.  * Lot's of error checking and logging of errors as well as normal
  20.  * operation. If anything goes wrong, it is logged and the session
  21.  * is aborted. 
  22.  *------------------------------------------------------------------*/
  23.  
  24. '@echo off'
  25. host = "ftp.sstar.com"
  26. name = ""
  27. password = ""
  28. seqfile  = 'f:\bbs\ftpfido.seq'
  29. inbound = 'd:\ftpin2'   /* Binkley or FD secure inbound */
  30. ftpin = 'F:\ftpin' /* Inbound for FTP mail */
  31. filein = 'I:\ftpin' /* Inbound for FTP files */
  32. ftpout = 'd:\ftpout' /* Outbound for FTP */
  33. errlog = 'f:\bbs\logs\error.log' /* a logfile for errors */
  34. bsy = 'f:\binkley\IHUB.BSY'      /* local file sent as remote busy flag */
  35. remotebsyname = 'IHUB.BSY'    /* remote name for above */
  36. avbps = 2000 /* Your average bps rate */
  37. flg = 'f:\bbs\logs\Doing_ftp.flg' /* process flag */
  38. logfile  = 'F:\bbs\logs\ftpfido.log' /* Drive containing logs */
  39. listfile  = 'F:\bbs\logs\ftplist.log'
  40. mailbundle = 'f:\ftpin\f349fff8.*' /* I only move mailbundles from ftpin to inbound. Change to *.* if you move all */
  41. bundlemail = 'f349fff8.*' /* Same thing as above minus path */
  42. ndyet = 'd:\ftpin\ndyet.flg' /* Use this flag to prevent Allfix from running to prevent tics w/o files and vice versa */
  43. tcpbin = 'd:\tcpip\bin' /* where hangup.cmd is located to terminate slip session */
  44. hangup = 0  /* whether to hangup or not */
  45. scrlgth = 25
  46.  
  47. 'mode co80,'||scrlgth
  48.  
  49. bttm2 = scrlgth - 2
  50. bttm3 = scrlgth - 3
  51.  
  52. total_received = 0
  53. total_sent = 0
  54. total_uls = 0
  55. total_files = 0
  56. sizethere = 0
  57. howmucht = 0
  58. howlongt = 0
  59. p = 6
  60. y = 0
  61.  
  62. esc = D2C(27)
  63. ansi_red = esc || '[1;31m' 
  64. ansi_green = esc || '[1;32m' 
  65. ansi_yellow = esc || '[1;33m' 
  66. ansi_blue = esc || '[1;34m' 
  67. ansi_lightblue = esc || '[1;36m' 
  68. ansi_white = esc || '[1;37m' 
  69. ansi_whonblue = esc || '[1;44m' 
  70. ansi_whonmag = esc || '[1;45m'
  71. ansi_whoncyan = esc || '[1;46m'
  72. ansi_normal = esc || '[0m'
  73.  
  74. UpperCase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  75. LowerCase = 'abcdefghijklmnopqrstuvwxyz'
  76.  
  77. Signal on Syntax Name ErrorStop
  78. Signal on Halt Name Abort
  79. Signal on Failure Name FailureStop
  80.  
  81. rc = stream(logfile,'C','open write')
  82.  
  83. call Lineout logfile ,date('N') Time('N') 'FTPFIDO starting up.'
  84.  
  85. Call CopyInfo
  86.  
  87. if RxFuncQuery("FtpLoadFuncs") then
  88.    do
  89.    rc = RxFuncAdd("FtpLoadFuncs","RxFtp","FtpLoadFuncs")
  90.    rc = FtpLoadFuncs(quiet)
  91.    end
  92.  
  93. if RxFuncQuery("SysLoadFuncs") then
  94.    do
  95.    rc = RxFuncAdd("SysLoadFuncs","RexxUtil","SysLoadFuncs")
  96.    rc = SysLoadFuncs()
  97.    end
  98.  
  99. if hangup = 1 then do
  100. if RxFuncQuery("rexxlibregister") then
  101.    do
  102.    rc = RxFuncAdd('rexxlibregister','rexxlib','rexxlibregister')
  103.    rc = rexxlibregister()
  104.    end
  105. end
  106.  
  107. /* Check for process flag */
  108. IF Stream(flg,'C', 'Query Exists') <>' ' Then
  109.     Do
  110.   say ansi_red '!Must be running already.' ansi_normal
  111. rc = lineout(logfile,' Must be running already.')
  112.  signal exit
  113.     end
  114. else
  115.  do
  116.  rc = stream(flg,'C','open write') /* Set process flag */
  117. if rc <> 'READY:' Then
  118.     Do
  119.   say ansi_red '!Error creating flagfile.' ansi_normal
  120. rc = lineout(logfile,'!Error creating flagfile.')
  121.   signal exit
  122.     end
  123.  rc = stream(flg,'C','close')
  124.  end
  125.  
  126. /* Check the busy flag */
  127. w = 0
  128. New=Directory(netout)
  129. do until w = 10 /* This sets 10 - 1min. cycles */
  130. IF Stream(fidobsy,'C', 'Query Exists') <>' ' Then
  131.     Do
  132.   say ansi_red '!Node is busy - waiting.' ansi_normal
  133. rc = lineout(logfile,'!Node is busy - waiting.')
  134.   Call SysSleep 60 /* wait 60 secs. */
  135.   w = w + 1
  136.   if w = 10 then exit /* exit after 10 mins. */
  137.   iterate
  138.     end
  139. else
  140.  do
  141.  rc = stream(fidobsy,'C','open write') /* Set local busy flag */
  142. if rc <> 'READY:' Then
  143.     Do
  144.   say ansi_red '!Error creating busy flag.' ansi_normal
  145.   rc = lineout(logfile,'!Error creating busyflag.')
  146.   signal exit
  147.     end
  148.  rc = stream(fidobsy,'C','close')
  149.  leave
  150.  end
  151. end /* do while */
  152.  
  153.     Call SysCurPos 0,21
  154.     say ansi_yellow 'Begin: 'Time('N') ansi_normal
  155.  
  156. if hangup = 1 then do
  157. killme = DosPid()
  158. New = Directory(tcpbin)
  159. 'start /fs /c /b hangup.cmd 'killme
  160. end
  161.  
  162. /* Get the latest send sequence*/
  163. seqstr = "0123456789abcdefghijklmnopqrstuvwxyz"
  164. daywk = "mo tu we th fr sa su"
  165.  
  166. /* Contains the day and sequence*/
  167. IF Stream(seqfile,'C', 'Query Exists') <>' ' Then
  168.   Do
  169.   line = LINEIN(seqfile)
  170.   day = WORD(line, 1)
  171.   if POS(day, daywk) = 0 then
  172.     day = "mo"
  173.   seq = WORD(line, 2)
  174.   seqno = POS(seq, seqstr)
  175.   if seqno = 0 then do
  176.     seq = "0"
  177.     seqno = 1
  178.   end
  179.  end
  180. else do
  181.   file = LINEOUT(seqfile, 'mo 0')
  182.   seqno = 1
  183. end
  184. file = LINEOUT(seqfile)
  185.  
  186. rc = FtpSetBinary('Binary')
  187.  
  188. /*------------------------------------------------------------------
  189.  * LOGON
  190.  *------------------------------------------------------------------*/
  191.  
  192. rc = FtpSetUser(host, name, password)
  193.  
  194. stime = time('e')
  195.  
  196. attached = FtpSys(siteinfo)
  197. Call SysCurPos 1,21
  198. say ansi_whonblue attached  ansi_normal
  199. len = length(attached)
  200. if len > 8 then                                               /* CFP!!! */
  201. do
  202.     Call SysCurPos 2,21
  203.     rc = lineout(logfile,' Login successful')
  204.     say ansi_whonblue 'Login successful ' ansi_normal
  205.     Call datetime
  206.  
  207.     rc = FtpChDir('..')                                         /* CFP!!! */
  208.  
  209.     rc = FtpPut(bsy,remotebsyname)
  210.     if err <> -1 & FTPERRNO <> '0' then
  211.     do
  212.     say ansi_red '!Error putting busy flag on remote.' ansi_normal
  213.     rc = lineout(logfile,'!Error putting busy flag on remote.')
  214.     signal abort
  215.     end
  216.  
  217. /*------------------------------------------------------------------
  218.  * Change to remote inbound directory.
  219.  *------------------------------------------------------------------*/
  220.  
  221.     rc = FtpChDir("in")                /* CFP!!!! */
  222.     if err <> -1 & FTPERRNO <> '0' then
  223.     do
  224.     say ansi_red '!Error changing directory on remote.' ansi_normal
  225.     rc = lineout(logfile,'!Error changing directory on remote.')
  226.     signal abort
  227.     end
  228.  
  229. /*------------------------------------------------------------------
  230.  * Send Files
  231.  *------------------------------------------------------------------*/
  232.  
  233. New=Directory(ftpout)
  234.  
  235. p = 5
  236.  
  237.     rc = SysFileTree('*.*',outfile.,"F")
  238.     if outfile.0 > 0 then
  239.     do
  240.         sizethere = 0
  241.     x = 1
  242.     do outfile.0    /* loop through all the files here */
  243.          Call datetime
  244.  
  245.           ennd = scrlgth - 4
  246.           if p > ennd then do
  247.             p = ennd
  248.             do until p = 5
  249.             Call SysCurPos p,0
  250.             say "                                                  "
  251.             p = p - 1
  252.             end /* do until */
  253.            end
  254.  
  255.         filename = filespec("name", word(outfile.x,5))
  256.         fullname = word(outfile.x,5)
  257.         if filename <> '' & LENGTH(filename) > 3 & word(outfile.x,3) <> 0 then
  258.         do
  259.             /* Make sure the sequence is correct*/
  260.         posfile = LASTPOS('.', filename) + 1
  261.         setseq = SUBSTR(filename, posfile)
  262.         fday = TRANSLATE(DELSTR(setseq, 3))
  263.         fseq = TRANSLATE(SUBSTR(setseq, 3, 1))
  264.         fseqno = POS(fseq, seqstr)
  265.  
  266.         /* Check if the days match*/
  267.         if day = fday then 
  268.           do
  269.         if fseqno > seqno then 
  270.             do
  271.           seqno = fseqno
  272.           seq = SUBSTR(seqstr, seqno, 1)
  273.             end
  274.           end
  275.            else do
  276.            day = fday
  277.            seqno = fseqno
  278.            if seqno = 0 then seqno = 1
  279.            seq = SUBSTR(seqstr, seqno, 1)
  280.             end
  281.  
  282.              remfile1 = DELSTR(filename, posfile)||day||seq
  283.  
  284.            Trunc = 0
  285.            Nuke = 1    
  286.  
  287.            Call Put filename fullname word(outfile.x,3) remfile1
  288.  
  289.         /* Update the sequence file*/
  290.         'erase 'seqfile
  291.         seqno = seqno + 1
  292.         seq = SUBSTR(seqstr, seqno, 1)
  293.         file = LINEOUT(seqfile, day' 'seq)
  294.         file = LINEOUT(seqfile)
  295.             end
  296.            else
  297.           do
  298.               say ansi_red '!'fullname' not found or 0 length.' ansi_normal
  299.           rc = lineout(logfile,'!'fullname' not found or 0 length.')
  300.           end
  301.        x = x + 1
  302.        p = p + 1
  303.     end /* Do loop */
  304.     end
  305.     if sizethere = '0' then
  306.     do
  307.         say ansi_yellow ' No mail/files to send at this time.' ansi_normal
  308.     rc = lineout(logfile,' No mail/files to send at this time')
  309.         p = p + 1
  310.     end
  311. end
  312.  
  313. /*------------------------------------------------------------------
  314.  * Change to remote outbound directory.
  315.  *------------------------------------------------------------------*/
  316.  
  317.     rc = FtpChDir("..")                                 /* CFP!!!! */
  318.     if err <> -1 & FTPERRNO <> '0' then
  319.     do
  320.     say ansi_red '!Error changing directory on remote.' ansi_normal
  321.     rc = lineout(logfile,'!Error changing directory on remote.')
  322.     signal abort
  323.     end
  324.     rc = FtpChDir("out")                                /* CFP!!!! */
  325.     if err <> -1 & FTPERRNO <> '0' then
  326.     do
  327.     say ansi_red '!Error changing directory on remote.' ansi_normal
  328.     rc = lineout(logfile,'!Error changing directory on remote.')
  329.     signal abort
  330.     end
  331.  
  332. /*------------------------------------------------------------------
  333.  * Get Mail.
  334.  *------------------------------------------------------------------*/
  335.  
  336.     New=Directory(ftpin)
  337.     rc = Ftpdir(bundlemail,infile.)  /* get list of files there for list */
  338.       if infile.0 > 0 & rc = 0 then
  339.    do
  340.       'del 'listfile '> nul: 2>&1'
  341.       rc = stream(listfile,'C','open write')
  342.        total_bytes = 0
  343.        do i = 1 to infile.0
  344.         filename = word(infile.i,9)
  345.         size = word(infile.i,5)
  346.         total_bytes = total_bytes + size
  347.         rc = LINEOUT(listfile, filename size)
  348.         if y < bttm2 then do
  349.         Call SysCurPos y,55
  350.         say ansi_whoncyan filename' -' size ansi_normal
  351.         end
  352.         y = y + 1
  353.        end
  354.         rc = stream(listfile,'C','close')
  355.         apxsecs = total_bytes%avbps
  356.         apxmins = apxsecs%60
  357.         Call SysCurPos bttm4,0
  358.         say ansi_whonmag 'Receiving 'infile.0  'mail file(s) 'total_bytes' bytes 'apxmins' avg. mins.' ansi_normal
  359.         rc = lineout(logfile,' Receiving 'infile.0 'mail file(s) 'total_bytes' bytes 'apxmins' avg. mins.')
  360.         bps = 2000
  361.         x = 1                       /* reset the pointer */
  362.  
  363.     /* time to get files here from There */
  364.      do infile.0
  365.  
  366.      Call datetime
  367.  
  368.       ennd = scrlgth - 4
  369.       if p > ennd then do
  370.         p = ennd
  371.         do until p = 5
  372.         Call SysCurPos p,0
  373.         say "                                                  "
  374.         p = p - 1
  375.         end /* do until */
  376.        end
  377.  
  378.             filename = word(infile.x,9)
  379.  
  380.             if filename = "incoming" then  x = x + 1  /* CFP!!!! */
  381.             if filename = "incoming" then iterate    /* CFP!!!! */
  382.  
  383.             Call Get filename word(infile.x,5)
  384.  
  385.         x = x + 1
  386.         p = p + 1
  387.      end /* Do loop */
  388.  end
  389.     else
  390.     do
  391.         Call SysCurPos p,0
  392.         rc = lineout(logfile,' No mail to get')
  393.         say ansi_yellow ' No mail to get.' ansi_normal
  394.     end
  395.  
  396. IF Stream(mailbundle,'C', 'Query Exists') <>' ' Then
  397.  do
  398.  /* 'start /fs/c/b procmail' */ /* Start mail tossing */
  399.  end
  400.  
  401. /*------------------------------------------------------------------
  402.  * Get Files
  403.  *------------------------------------------------------------------*/
  404.  
  405.     New=Directory(filein)
  406.     if New = filein then
  407.   do
  408.     rc = Ftpdir('*.*',infile.)  /* get list of files there for list */
  409.       if infile.0 > 0 & rc = 0 then
  410.    do
  411.       'del 'listfile '> nul: 2>&1'
  412.       rc = stream(listfile,'C','open write')
  413.        total_bytes = 0
  414.        do i = 1 to infile.0
  415.         filename = word(infile.i,9)
  416.         size = word(infile.i,5)
  417.         total_bytes = total_bytes + size
  418.         rc = LINEOUT(listfile, filename size)
  419.         if y < bttm2 then do
  420.         Call SysCurPos y,55
  421.         say ansi_whoncyan filename' -' size ansi_normal
  422.         end
  423.         y = y + 1
  424.        end
  425.         rc = stream(listfile,'C','close')
  426.         apxsecs = total_bytes%avbps
  427.         apxmins = apxsecs%60
  428.         Call SysCurPos bttm3,0
  429.         say ansi_whonmag 'Receiving 'infile.0  'file(s) 'total_bytes' bytes 'apxmins' avg. mins.' ansi_normal
  430.         rc = lineout(logfile,' Receiving 'infile.0 'file(s) 'total_bytes' bytes 'apxmins' avg. mins.')
  431.         bps = 2000
  432.         x = 1                       /* reset the pointer */
  433.  
  434.     /* time to get files here from There */
  435.      do infile.0
  436.  
  437.      Call datetime
  438.  
  439.       ennd = scrlgth - 4
  440.       if p > ennd then do
  441.         p = ennd
  442.         do until p = 5
  443.         Call SysCurPos p,0
  444.         say "                                                  "
  445.         p = p - 1
  446.         end /* do until */
  447.        end
  448.  
  449.             filename = word(infile.x,9)
  450.  
  451.             if filename = "incoming" then  x = x + 1  /* CFP!!!! */
  452.             if filename = "incoming" then iterate    /* CFP!!!! */
  453.  
  454.             Call Get filename word(infile.x,5)
  455.  
  456.         x = x + 1
  457.         p = p + 1
  458.      end /* Do loop */
  459.  end
  460.     else
  461.     do
  462.         Call SysCurPos p,0
  463.         rc = lineout(logfile,' No files to get')
  464.         say ansi_yellow ' No files to get.' ansi_normal
  465.    end
  466.   end
  467.      else
  468.       do
  469.        say ansi_red '!Error changing to 'filein'.' ansi_normal
  470.        rc = lineout(logfile,'!Error changing to 'filein)
  471.       end
  472.  
  473. /*------------------------------------------------------------------
  474.  * Change to remote root directory, remove busy flag and logoff.
  475.  *------------------------------------------------------------------*/
  476.  
  477.     rc = FtpChDir('..')
  478.     if err <> -1 & FTPERRNO <> '0' then
  479.     do
  480.     say ansi_red '!Error changing directory on remote.' ansi_normal
  481.     rc = lineout(logfile,'!Error changing directory on remote.')
  482.     end
  483.     rc = FtpDelete(remotebsyname)
  484.     if err <> -1 & FTPERRNO <> '0' then
  485.     do
  486.     say ansi_red '!Error deleting busy flag from remote.' ansi_normal
  487.     rc = lineout(logfile,'!Error deleting busy flag from remote.')
  488.     end
  489.  
  490.     rc = FtpLogoff()
  491.     rc = FtpDropFuncs()
  492.  
  493.     signal done
  494.  
  495. end /* Login loop */
  496. else
  497. do
  498. Call SysCurPos 1,28
  499.     say ansi_red '!Login failed... session aborted' ansi_normal
  500.     rc = lineout(logfile,'!Login failed... session aborted')
  501.     signal abort
  502. end
  503.  
  504.  
  505. /*------------------------------------------------------------------
  506.  * SubRoutines
  507.  *------------------------------------------------------------------*/
  508.  
  509. DateTime:
  510.     Call SysCurPos 3,21
  511.     say ansi_white date('N') Time('N') ansi_normal
  512. Return
  513.  
  514. /*------------------------------------------------------------------
  515.  * PUT
  516.  *------------------------------------------------------------------*/
  517.  
  518. Put:
  519. parse arg filehere fullname sizehere filethere
  520. o = 1
  521.  
  522. Call SysCurPos p,0
  523.  
  524. filethere = translate(filethere, LowerCase, UpperCase)
  525. if filehere <> filethere then
  526.  do
  527.    rc = lineout(logfile,' sending 'fullname '- 'sizehere 'bytes as 'filethere)
  528.    say ansi_green 'Sending 'filehere ' - 'sizehere' bytes as 'filethere ansi_normal
  529.  end
  530. else
  531.   do
  532.     rc = lineout(logfile,' sending 'fullname '- 'sizehere 'bytes')
  533.     say ansi_green 'Sending 'filehere ' - 'sizehere' bytes ' ansi_normal
  534.   end
  535.  
  536.   ustart = time('e')
  537.  
  538.   err = FtpPut(fullname, filethere, 'binary')
  539.  
  540.   uelapsed = time('e')
  541.  
  542.   howmuch = strip(uelapsed-ustart,,0)
  543.   bps = strip(format(sizehere/howmuch,10,0))
  544.  
  545.   if err = -1 & FTPERRNO = '0' then
  546.   do
  547.   /* add code to  test for good transfer by filesize */
  548.     rc = FtpDir(filethere,test.)     /* get size from remote */
  549.     if test.0 = 1 then /* it did get there  */
  550.      do
  551.         sizethere = word(test.1,5)
  552.      if sizehere = sizethere then /* if the same size, delete or truncate if necessary */
  553.       do
  554.       p = p + 1
  555.       Call SysCurPos p,0
  556.           total_sent = total_sent + sizethere /* get size for report */
  557.            howmucht = howmucht + howmuch
  558.            total_uls = total_uls + 1
  559.        Select
  560.             When Trunc = 1 then
  561.             do
  562.             rc = lineout(logfile,' Successful - Truncating 'filehere)
  563.             say ansi_yellow ' Truncating 'filehere ansi_normal
  564.             rc=SysFileDelete(fullname)
  565.             IF rc <> 0 Then
  566.               do
  567.             say ansi_red '!Error del/truncating 'fullname ansi_normal
  568.             rc = lineout(logfile,'!Error del/truncating 'fullname
  569.               end
  570.               else do
  571.               call stream fullname, 'C', 'open write'
  572.               call stream fullname, 'C', 'close'
  573.               end
  574.             end
  575.             When Nuke = 1 then
  576.             do
  577.             rc = lineout(logfile,' Successful - Deleting 'fullname)
  578.             say ansi_yellow ' Deleting 'fullname ansi_normal
  579.             rc = SysFileDelete(fullname)
  580.             IF rc <> 0 Then
  581.               do
  582.             say ansi_red '!Error deleting 'fullname ansi_normal
  583.             rc = lineout(logfile,'!Error deleting 'fullname
  584.               end
  585.             end
  586.        otherwise
  587.        end /* Select */
  588.         p = p + 1
  589.         Call SysCurPos bttm2,0
  590.         say "                                                  "
  591.         Call SysCurPos bttm2,0
  592.         say ansi_whonblue 'Sent 'total_uls 'file(s) 'total_sent 'bytes 'howmucht%60 'min. 'strip(format(howmucht//60,3,0)) 'secs.' ansi_normal
  593.         Call SysCurPos p,0
  594.         say ansi_lightblue 'Sent 'filehere '- 'howmuch%60 'min. 'strip(format(howmuch//60,3,0)) 'secs. 'bps 'bps.' ansi_normal
  595.         rc = lineout(logfile,' sent 'filehere' - 'howmuch%60 'min. 'strip(format(howmuch//60,3,0)) 'secs. Baud = 'bps)
  596.       end /* size */
  597.         else
  598.           do
  599.             rc = lineout(logfile,'!Error in size - Deleting  'filethere 'from inbound')
  600.             say ansi_red '!Error in size - Deleting  'filethere 'from inbound' ansi_normal
  601.             rc = FtpDelete(filethere)
  602.             if err <> -1 & FTPERRNO <> '0' then
  603.             do
  604.             say ansi_red '!Error deleting 'filethere 'from remote.' ansi_normal
  605.             rc = lineout(logfile,'!Error deleting 'filethere 'from remote.')
  606.             signal xabort
  607.             end
  608.           end
  609.      end /* test */
  610.     else
  611.        do
  612.        say ansi_red '!Error in filetest' ansi_normal
  613.         rc = lineout(logfile,'!Error in filetest!')
  614.        signal xabort
  615.        end
  616.   end
  617.   else
  618.    do
  619.     say ansi_red '!FTP returned error 'FTPERRNO ansi_normal
  620.     rc = lineout(logfile,'!FTP returned error 'FTPERRNO)
  621.     signal xabort
  622.     end
  623.  
  624. Return
  625.  
  626. /*------------------------------------------------------------------
  627.  * GET
  628.  *------------------------------------------------------------------*/
  629.  
  630. Get:
  631. parse arg filename filesize
  632.  
  633. Call SysCurPos p,0
  634.  
  635.             say ansi_blue 'Recieving 'filename '- ' filesize 'bytes ' ansi_normal
  636.             start = time('e')
  637.             err = FtpGet(filename, filename,"binary")    /* Transfer the file */
  638.             elapsed = time('e')
  639.  
  640.             if err = -1 & FTPERRNO = '0' then
  641.              do
  642.              sizehere = stream(filename,'C','query size')    /* get the filesize here */
  643.              if sizehere = filesize then
  644.               do
  645.             Call SysCurPos p,0
  646.             say "                                                  "
  647.             Call SysCurPos p,0
  648.             howlong = strip(elapsed-start,,0)
  649.             bps = strip(format(sizehere/howlong,10,0))
  650.             say ansi_lightblue 'Recieved 'filename '- 'howlong%60 'min. 'strip(format(howlong//60,3,0)) 'secs. 'bps 'bps.' ansi_normal
  651.             rc = lineout(logfile,' received 'filename' - 'sizehere' - 'howlong%60 'min. 'strip(format(howlong//60,3,0)) 'secs. Baud = 'bps)
  652.                 total_received = total_received + sizehere
  653.                 total_files = total_files + 1
  654.                 rc = FtpDelete(filename)
  655.                 if err <> -1 & FTPERRNO <> '0' then
  656.                 do
  657.                 say ansi_red '!Error deleting 'filename 'from remote.' ansi_normal
  658.                 rc = lineout(logfile,'!Error deleting 'filename 'from remote.')
  659.                 end
  660.                 Call SysCurPos bttm2,0
  661.                 say "                                                  "
  662.                 Call SysCurPos bttm2,0
  663.                 howlongt = howlongt + howlong
  664.                 say ansi_whonblue 'Received 'total_files 'file(s) 'total_received 'bytes 'howlongt%60 'min. 'strip(format(howlongt//60,3,0)) 'secs.' ansi_normal
  665.                 if bps < 500 & filesize > 50000 then
  666.                 do
  667.                 say ansi_red '!Something ain''t right!! too slow??' ansi_normal
  668.                 rc = lineout(logfile,'!Something went wrong with bps')
  669.                 signal xabort
  670.                 end
  671.               end /* size */
  672.              else
  673.              do
  674.              say ansi_red '!Error in filesize' ansi_normal
  675.              rc = lineout(logfile,'!Error in filesize')
  676.              signal xabort
  677.              end
  678.              end
  679.             else
  680.             do
  681.             say ansi_red '!FTP returned error 'FTPERRNO ansi_normal
  682.             rc = lineout(logfile,'!FTP returned error 'FTPERRNO)
  683.             signal xabort
  684.             end
  685.  
  686. Return
  687.  
  688. /*------------------------------------------------------------------
  689.  * Aborts
  690.  *------------------------------------------------------------------*/
  691.  
  692. Xabort:
  693. Call SysCurPos p,0
  694. say ansi_red '!File transfer failed..' ansi_normal
  695. rc = lineout(logfile,'!File transfer failed..')
  696.  
  697.     rc = FtpChDir('..')
  698.     if err <> -1 & FTPERRNO <> '0' then
  699.     do
  700.     say ansi_red '!Error changing directory on remote.' ansi_normal
  701.     rc = lineout(logfile,'!Error changing directory on remote.')
  702.     end
  703.     rc = FtpDelete(remotebsyname)
  704.     if err <> -1 & FTPERRNO <> '0' then
  705.     do
  706.     say ansi_red '!Error deleting busy flag from remote.' ansi_normal
  707.     rc = lineout(logfile,'!Error deleting busy flag from remote.')
  708.     end
  709.  
  710. Abort:
  711. Call SysCurPos 3,28
  712. say ansi_red '!Session Aborted' ansi_normal
  713. rc = lineout(logfile,'!Session Aborted')
  714.  
  715.  rc = stream(ndyet,'C','open write') /* Set not done yet flag */
  716. if rc <> 'READY:' Then
  717.     Do
  718.    say ansi_red '!Error creating ndyet flag.' ansi_normal
  719.    rc = lineout(logfile,'!Error creating ndyet flag.')
  720.     end
  721.  rc = stream(ndyet,'C','close')
  722.  
  723.     rc = FtpChDir('..')                                         /* CFP!!! */
  724.     rc = FtpDelete(remotebsyname)
  725.  
  726. signal Abort1
  727.  
  728. /*------------------------------------------------------------------
  729.  * DONE
  730.  *------------------------------------------------------------------*/
  731.  
  732. Done:
  733.  
  734.         /* remove ndyet flag */
  735.      IF Stream(ndyet,'C', 'Query Exists') <>' ' Then
  736.       Do
  737.       'del 'ndyet' > nul: 2>&1'
  738.        IF rc <> 0 Then
  739.        Do
  740.        say ansi_red '!Error deleting ndyet.flg' ansi_normal
  741.        rc = lineout(logfile,'!Error deleting ndyet.flg')
  742.        end
  743.       end
  744.  
  745. Abort1:
  746.  
  747. Call SysCurPos bttm3,0
  748. Say "                                                                               "
  749. Call SysCurPos bttm2,0
  750. Say "                                                                               "
  751. Call SysCurPos bttm3,0
  752.  
  753. etime = time('e')
  754.  
  755. totalxfertime = howmucht + howlongt
  756.  
  757. say ansi_yellow ' Sent 'total_sent 'bytes, received 'total_received 'bytes in 'totalxfertime%60 'minutes, 'strip(format(totalxfertime//60,6,0)) 'seconds. 'etime ansi_normal
  758. rc = lineout(logfile, ' $Sent 'total_sent 'bytes, received 'total_received 'bytes in 'totalxfertime%60 'minutes, 'strip(format(totalxfertime//60,10,0)) 'seconds. 'etime )
  759. if total_sent > 0 then
  760. do
  761. say ansi_yellow ' Total u/l time - 'howmucht%60 'min. 'strip(format(howmucht//60,3,0))' secs.  'strip(format(total_sent/howmucht,10,0))' avg. u/l bps.' ansi_normal
  762. rc = lineout(logfile, ' Total u/l time - 'howmucht%60 'min. 'strip(format(howmucht//60,3,0))' secs.  'strip(format(total_sent/howmucht,10,0))' avg. u/l bps.')
  763. end
  764. if total_received > 0 then
  765. do
  766. say ansi_yellow ' Total d/l time - 'howlongt%60 'min. 'strip(format(howlongt//60,3,0))' secs.  'strip(format(total_received/howlongt,10,0))' avg. d/l bps.' ansi_normal
  767. say ansi_yellow ' Sent 'total_uls 'files(s) Received 'total_files 'file(s).' ansi_normal
  768. rc = lineout(logfile, ' Total d/l time - 'howlongt%60 'min. 'strip(format(howlongt//60,3,0))' secs.  'strip(format(total_received/howlongt,10,0))' avg. d/l bps.')
  769. rc = lineout(logfile, ' Sent 'total_uls 'file(s) Received 'total_files 'file(s).')
  770. end
  771.  
  772.           /* Clearing Local bsy Flag*/
  773.         New=Directory(netout)
  774.         'del 'fidobsy '> nul: 2>&1'
  775.        IF rc <> 0 Then
  776.        Do
  777.        say ansi_red '!Error deleting 'fidobsy ansi_normal
  778.        rc = lineout(logfile,'!Error deleting 'fidobsy)
  779.        end
  780.  
  781.         /* remove process flag */
  782.       'del 'flg '> nul: 2>&1'
  783.        IF rc <> 0 Then
  784.        Do
  785.        say ansi_red '!Error deleting 'flg ansi_normal
  786.        rc = lineout(logfile,'!Error deleting 'flg)
  787.        end
  788.  
  789. call Lineout logfile ,date('N') Time('N') 'FTPFIDO closing down.'
  790.  
  791. rc = stream(logfile,'C','close')
  792.  
  793. exit
  794.  
  795.  
  796. CopyInfo:
  797.  
  798. Call SysCls
  799.  
  800. Say esc || '[0;1;46m    ░░░░▒▒▒▒▓▓▓▓████'esc || '[40m'
  801. Say '      'esc || '[36mFTPFido'
  802. Say '   By Jerry Gause'
  803. Say 'Warped Software'
  804. Say esc || '[37;46m████▓▓▓▓▒▒▒▒░░░░    'esc || '[40m'
  805. Say ansi_normal
  806. Return
  807.  
  808. FailureStop:
  809. parse upper source tst
  810.       say ansi_red 'A Failure ('RC') has occurred on Line 'Sigl' in 'tst ansi_normal
  811.       say 'ftpfido has Failure Exited'
  812.       call Lineout errlog ,date('N') Time('N') ':  ftpfido ,  A Failure ('RC') has occurred on Line 'Sigl' in 'tst
  813.    Signal Exit
  814.  
  815. ErrorStop:
  816. parse upper source tst
  817.       say ansi_red 'An Error ('RC') has occurred on Line 'Sigl' in 'tst ansi_normal
  818.       say 'ftpfido has Error Exited'
  819.       call Lineout errlog ,date('N') Time('N') ':  ftpfido , An Error ('RC') has occurred on Line 'Sigl' in 'tst
  820.  
  821. exit:
  822. if hangup = 1 then do
  823. New = Directory(tcpbin)
  824. 'start /fs /c /b hangup.cmd 'killme
  825. end
  826. rc = stream(errlog,'C','close')
  827. rc = stream(logfile,'C','close')
  828. exit
  829.