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

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