home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / ftpfid17.zip / FTPFID17.CMD < prev    next >
OS/2 REXX Batch file  |  1996-09-16  |  32KB  |  1,013 lines

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