home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mailftp.zip / ftp-sstar.cmd < prev    next >
OS/2 REXX Batch file  |  1995-12-08  |  14KB  |  330 lines

  1. /* You will need to look over the whole script and make modifications */
  2. /* to anything that is specific for your site. This script looks for */
  3. /* mail here and sends it to George's system and picks up everything on */
  4. /* hold for me there. It works for me (wish I had commented it better now...) */
  5. /* I can't say it will work for you.*/ /* Good luck. */
  6.  
  7. /* This script was made up of the original file contained within FtpFido.Zip   *
  8.  * With the help of examples from all those generous folks out there releasing *
  9.  * Rexx scripts without compiling I say thanks!  This mod is released in the   *
  10.  * same spirit in hopes someone out there can make it even better! 27-Oct-1995 */
  11.  
  12. /*                 Modified to connect to Southern Star via IHUB account for same           */
  13. /************************************************************************************************
  14.  
  15. * 10/95 - started from the command line in an OS/2 window, using PPPDIAL.CMD as
  16. * the script launched from the Dialer in Warp's Bonus Pack... more to come as
  17. * I have time and gain more experience... Hopefully I'll at least complete enough
  18. * logging to hold over until some good error trapping can be implimented 
  19. * - rgwallen@datasync.com - 1995
  20.  
  21. * Scripts working in conjunction with same and that are required:
  22.   - STARTPPP.CMD            Startup Script to begin session
  23.   - PPPDIAL.CMD [V2.7]        available from many OS/2 ftp sites by Don Russell
  24.                     send e-mail to: drussell@direct.ca
  25.   - FTP-SSTAR.CMD        ftp script to connect to IHUB (req' RXFTP.DLL)
  26.   - DATASYNC.RSP            Response file used with PPPDIAL
  27.  
  28. o  rexx script to get FidoNet mail from Ftp.Sstar.Com
  29.  
  30. o  this script attempts to keep a running log of files received 
  31.  
  32. o  added date, time and formatted output to log...
  33.  
  34. -  Need desperately adding err trapping routines for: 17-Nov-1995
  35.    o failed ftp login session - completed
  36.    . drop connection during ftp trans - need this asap!
  37.    . need associated logging for error routines
  38.  
  39. -  need to add dialer vars for provider connection and login - now using PPPDIAL
  40. ************************************************************************************************/
  41.  
  42. /* trace  ?A */
  43.  
  44. trace off
  45.  
  46. /*------------------------------------------------------------------
  47.  * load functions, if needed
  48.  *------------------------------------------------------------------*/
  49. if RxFuncQuery("FtpLoadFuncs") then
  50.    do
  51.    rc = RxFuncAdd("FtpLoadFuncs","RxFtp","FtpLoadFuncs")
  52.    rc = FtpLoadFuncs(quiet)
  53.    rc = FtpSetBinary('Binary')                        /* set all transfers to binary */
  54.    end
  55.  
  56. if RxFuncQuery("SysLoadFuncs") then
  57.    do
  58.    rc = RxFuncAdd("SysLoadFuncs","RexxUtil","SysLoadFuncs")
  59.    rc = SysLoadFuncs()
  60.    end
  61.  
  62.    rc = FtpVersion(prtver)                            /* Get RxFTP version from DLL */
  63.  
  64. call syssleep (5)                                /* delay startup to ensure PPP session completes */
  65. version = ".43"                                    /* Setup constants for this session */
  66. provider = "datasync"
  67. NumToDial = "476-8154"
  68. ipremote = ""
  69. iplocal = ""
  70.  
  71. /* ALL Pathnames used below must exist! - no checking is performed so edit to meet requirements */
  72.  
  73. mailhost = "ftp.*****.com"                            /* ftp site name */
  74. name = "****.***"                                /* your account name for IHUB */
  75. password = "*****"                                /* your session password for IHUB */
  76. ftpinbound = "/ihub/****_***/in"                        /* rem unix format for ftp inbound */
  77. ftpoutbound = "/ihub/****_***/out"                    /* ftp site outbound */
  78. ftphome = "/ihub/****_***"                            /* ftp site home */
  79. inbound = "c:\adept\mailer\ftpinbound"                    /* local inbound to receive */
  80. outbound = "c:\adept\mailer\sstar"                    /* local outbound to send */
  81. home = "c:\adept\mailer"                            /* location of ihub.bsy file */
  82. tossinbound = "c:\adept\mailer\password"                /* inbound for mail processer */
  83. log = "c:\logs\fidoFtp.log"                            /* logfile location & name */
  84. sendmail = "03a97af6.*"                            /* archived filename for mail to uplink */
  85. domailflag = "c:\adept\mailer\flags\do_mail.flg"            /* semaphore to allow mail script to run */
  86. doftpflag = "c:\adept\mailer\flags\doing_ftp.flg"            /* ftp insession semaphore */
  87.  
  88. /************************************************************************************************
  89. * You shouldn't have to change anything below - if you are familiar with Rexx have at it!       *
  90. ************************************************************************************************/
  91.  
  92.    say                                        /* Introduction */
  93.    say "Ftp-Sstar Rexx Script, Version "version
  94.    say "Created in Nov of 1995, This program is freeware"
  95.    say "to promote Team OS/2 style Rexx support/sharing"
  96.    say
  97.    say "RxFtp DLL Version used is v"prtver
  98.    say
  99.  
  100. total_received = 0                                /* reset counters for this session */
  101. total_sent = 0
  102. total_files = 0
  103. Verbose   = 0
  104.                                             /* initialize error trapping vars */
  105. rxFtpErr = 0
  106. rxFtp.FTPSERVICE    = 10
  107. rxFtp.FTPHOST       = 11
  108. rxFtp.FTPSOCKET     = 12
  109. rxFtp.FTPCONNECT    = 13
  110. rxFtp.FTPLOGIN      = 14
  111. rxFtp.FTPABORT      = 15
  112. rxFtp.FTPLOCALFILE  = 16
  113. rxFtp.FTPDATACONN   = 17
  114. rxFtp.FTPCOMMAND    = 18
  115. rxFtp.FTPPROXYTHIRD = 19
  116. rxFtp.FTPNOPRIMARY  = 20
  117.  
  118. 'echo. >'doftpflag                                /* semaphore used during ftp session */
  119. elapsed = substr(time('e'),9,1)
  120. day = left(date('E'),2)                            /* logfile day formatted leading 0 */
  121. mon = left(date('M'),3)                            /* logfile month formatted */
  122.  
  123. rc = stream(log,'C','open write')                        /* create if not exist and write to log */
  124.  
  125. rc = lineout(log,' ')
  126. rc = lineout(log,''day' 'mon' 'time()' FTP begin, FtpSys Rexx OS/2')
  127. rc = lineout(log,''day' 'mon' 'time()' FTP RxFtp DLL version is v'prtver)
  128. rc = lineout(log,''day' 'mon' 'time()' FTP Attempting FTP linkup with' mailhost)
  129. rc = FtpSetUser(mailhost, name, password)
  130.  
  131. attached = FtpSys(siteinfo)                            /* get site info */
  132. say attached
  133.  
  134. rc = lineout(log,''day' 'mon' 'time()' FTP System Info 'attached)
  135.  
  136. len = length(attached)
  137. say 'len = 'len
  138.  
  139. if len > 8 then
  140. do
  141.     rc = lineout(log,''day' 'mon' 'time()' FTP Rexx System Login to 'mailhost 'successful')
  142.     say 'Login successful'
  143.     rc = FtpChDir(ftphome)                            /* change to remote home directory */
  144.     call directory home
  145.     rc = lineout(log,''day' 'mon' 'time()' FTP Posting ihub.bsy flag into IHUB home directory')
  146.     say ' Posting ihub.bsy flag into IHUB home directory'
  147.     rc = FtpPut('ihub.bsy','ihub.bsy')                    /* Post ihub.bsy flag */
  148.  
  149.     call flofiles                /* check for other archived mail files to send sstar.com */
  150.     call directory outbound
  151.     rc = SysFileTree(sendmail,outfile.,"F")            /* Change to match your uplinks mail */
  152.     if outfile.0 > 0 then
  153.     do
  154.     rc = FtpChDir(ftpinbound)                        /* change to rem inbound */
  155.     call directory outbound                            /* change to local outbound */
  156.         rc = lineout(log,''day' 'mon' 'time()' FTP sending 'outfile.0' files')
  157.         say ' sending 'outfile.0' files'
  158.     x = 1
  159.         do outfile.0                                /* loop through all the files here */
  160.             rc = lineout(log,''day' 'mon' 'time()' FTP sending 'word(outfile.x,5))
  161.             say ' sending 'word(outfile.x,5) ' - 'word(outfile.x,3)' bytes'
  162.             filename = filespec("name", word(outfile.x,5))
  163.             rc = FtpPut(filename, filename, 'binary')
  164.  
  165.             /* add code to  test for good transfer by filesize */
  166.             rc = FtpDir(filename,test.)                /* get size from remote */
  167.             if test.0 = 1 then                        /* it did get there  */
  168.             do
  169.                 sizethere = word(test.1,5)
  170.                 sizehere = word(outfile.x,3)
  171.                 if sizehere = sizethere then                /* if the same size, delete */
  172.                   do
  173.                     total_sent = total_sent + sizethere        /* get size for report */
  174.                     rc = lineout(log,''day' 'mon' 'time()' FTP Successful - Deleting 'word(outfile.x,5))
  175.                     say ' Deleting 'outfile.x
  176.                     rc = SysFileDelete(word(outfile.x,5))
  177.                   end
  178.                 else
  179.                   do
  180.                     rc = lineout(log,''day' 'mon' 'time()' FTP UN-Successful - Deleting 'word(outfile.x,5) 'from inbound')
  181.                     say ' Deleting 'outfile.x
  182.                     SysFileDelete(word(outfile.x,5))
  183.                   end
  184.             end
  185.             x = x + 1                                /* go to the next file */
  186.         end
  187.     end
  188.     else
  189.     do
  190.         say 'nothing to send at this time'
  191.         rc = lineout(log,''day' 'mon' 'time()' FTP Nothing to send at this time')
  192.     end
  193.     rc = FtpChDir(ftpoutbound)                        /* change to remote outbound */
  194.     call directory inbound
  195.     rc = Ftpdir('*.*',infile.)                        /* get list of files there for transfer */
  196.     x = 1                                        /* reset the pointer */
  197.     if infile.0 > 1 then
  198.     do
  199.         say ' Receiving 'infile.0 -1 'file(s)'
  200.         rc = lineout(log,''day' 'mon' 'time()' FTP Receiving 'infile.0 -1 'file(s)')
  201.     end
  202.     if infile.0 > 1 & rc = 0 then
  203.                                             /* time to get files here from There */
  204.     do infile.0
  205.         test = pos('incoming',infile.x)                /* see if "incoming"  is the next file */
  206.         if test = 0 then                            /* if it isn't, transfer the file */
  207.         do
  208.             filename = word(infile.x,9)
  209.             say ' Recieving 'filename '- 'word(infile.x,5) 'bytes'
  210.             start = time('e')
  211.             rc = FtpGet(filename, filename,"binary")        /* Transfer the file */
  212.             elapsed = time('e')
  213.             sizehere = stream(filename,'C','query size')    /* get the filesize here */
  214.             transfilespeed = sizehere / (elapsed - start)
  215.             rc = lineout(log,''day' 'mon' 'time()' FTP received 'filename '-' sizehere' bytes received at 'format(transfilespeed,5,1) 'cps')
  216.             if sizehere = word(infile.x,5) then
  217.             do
  218.                 total_received = total_received + sizehere
  219.                 say ' Deleting 'filename
  220.                 rc = lineout(log,''day' 'mon' 'time()' FTP Deleting 'filename)
  221.                 rc = FtpDelete(filename)
  222.                 total_files = total_files + 1
  223.                 say ' Received 'total_files 'file(s)'
  224.             end
  225.         end
  226.         x = x + 1
  227.     end
  228.     else
  229.     do
  230.         rc = lineout(log,''day' 'mon' 'time()' FTP No files to get')
  231.         say ' No files to get'
  232.     end
  233.     rc = FtpChDir(ftphome)                            /* change to remote home dir */
  234.     rc = FtpDelete('ihub.bsy')                        /* delete semaphore on remote */
  235.     rc = lineout(log,''day' 'mon' 'time()' FTP Deleting ihub.bsy')
  236.     rc = FtpLogoff()
  237.  
  238. end
  239. else
  240. do
  241.     say '!Login failed... session aborted'
  242.     rc = lineout(log,''day' 'mon' 'time()' FTP !Login failed... session aborted')
  243. end
  244.  
  245. Abort:
  246. if aborted = 1 then rc = lineout(log,''day' 'mon' 'time()' FTP File transfer failed... Session Aborted')
  247.  
  248. call directory 'c:\tcpip\bin'                        /* make sure the drive is correct */
  249. 'ppp com2 exit'
  250. call syssleep 3
  251.  
  252. if total_files > 0 then
  253.     'echo. >'domailflag                            /* semaphore to check for to launch your tosser */
  254.  
  255. total = total_sent+total_received
  256.  
  257. elapsed = time('e')
  258. avgcps = total / elapsed
  259.  
  260. say ' Sent 'total_sent 'bytes, received 'total_received 'bytes in 'elapsed%60 'minutes, 'elapsed//60 ' seconds.'
  261. say ' Averaging 'format(avgcps,5,1)' cps for this session'
  262. rc = lineout(log,''day' 'mon' 'time()' FTP Sent 'total_sent 'bytes, received 'total_received 'bytes in 'elapsed%60 'minutes, 'format(elapsed//60,5,1) 'seconds.')
  263. rc = lineout(log,''day' 'mon' 'time()' FTP Averaging 'format(avgcps,5,1) 'cps for this session')
  264. rc = lineout(log,''day' 'mon' 'time()' FTP received 'total_files 'file(s)')
  265.  
  266. /* adding logic to copy files from ftpincoming to protected inbound for processing */
  267.  
  268. if total_files > 1 then
  269.     do
  270.     rc = lineout(log,''day' 'mon' 'time()' FTP Moving files from 'inbound' to 'tossinbound)
  271.     say 'Moving files from 'inbound' to 'tossinbound '...'
  272.     call directory inbound
  273.     PARSE VAR tossinbound drive ':' tossinbound            /* strip drive designator so move will work */
  274.     'move *.* 'tossinbound                            /* move files in ftp rec'ing dir to tosser inbound */
  275.     end
  276.  
  277. rc = lineout(log,''day' 'mon' 'time()' FTP end session, FtpSys Rexx OS/2 v'prtver)
  278.  
  279. say ' FTP end session, FtpSys Rexx OS/2 v'prtver
  280.  
  281. rc = stream(log,'C','close')
  282.  
  283. call syssleep (5)
  284. call directory 'c:\tcpip\bin'
  285. 'erase 'doftpflag                                /* Delete semaphore so FTP1 can terminate */
  286. exit                                            /* window will close when parent process terminates */
  287.  
  288. /* ------------------------procedure------------------------ */
  289.  
  290. FloFiles:
  291.  
  292. rc = FtpChDir(ftpinbound)                            /* cd to remote inbound */
  293. call directory outbound                            /* cd to local outbound */
  294. rc = SysFileTree(sendmail,files.,"F")                    /* send all files for sstar */
  295. say 'total files 'files.0
  296. if files.0 > 0 then
  297. do
  298.     rc = lineout(log,''day' 'mon' 'time()' FTP sending 'files.0' files')
  299.     say ' sending 'files.0' files'
  300.     x = 1
  301.     do files.0                                    /* loop through all the files here */
  302.         rc = lineout(log,''day' 'mon' 'time()' FTP sending 'word(files.x,5))
  303.         say ' sending 'word(files.x,5) ' - 'word(files.x,3)' bytes'
  304.         filename = filespec("name", word(files.x,5))
  305.         rc = FtpPut(filename, filename, 'binary')
  306.  
  307.              /* add code to test for good transfer by filesize */
  308.         rc = FtpDir(filename,test.)                    /* get size from remote */
  309.         if test.0 = 1 then                            /* it did get there  */
  310.         do
  311.             sizethere = word(test.1,5)
  312.             sizehere = word(files.x,3)
  313.             if sizehere = sizethere then                /* if the same size, delete */
  314.             do
  315.                 total_sent = total_sent + sizethere        /* get size for report */
  316.                 rc = lineout(log,''day' 'mon' 'time()' FTP Successful - Deleting 'word(files.x,5))
  317.                 say ' Deleting 'files.x
  318.                 rc = SysFileDelete(word(files.x,5))
  319.             end
  320.         end
  321.         x = x + 1                                /* go to the next file */
  322.     end
  323. end
  324. return
  325.  
  326.  
  327.  
  328.  
  329.  
  330.