home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / spewnew.zip / SpewNew.cmd < prev    next >
OS/2 REXX Batch file  |  1998-04-16  |  5KB  |  113 lines

  1. /*  A REXX/FTP routine to copy **new** files from LOCAL site to REMOTE site */
  2. /* */
  3. /*  This routine finds all the files with the archive bit set on LOCAL and */
  4. /*  ftp's them to the equivalent spot on REMOTE.  It then turns off the */
  5. /*  archive bit on the files once they have been transferred. */
  6. /* */
  7. /*  Usage:     SPEWNEW \LOCALDIR ftp.remote.ca/pub/remote */
  8. /*  where '\LOCALDIR' is the local directory root to begin searching down from*/
  9. /*        'ftp.remote.ca' is the ftp server to reach */
  10. /*        '/pub/remote' is the remote directory root on the remote server */
  11. /* */
  12. /*  You must have the IBM EWS rexx FTP module called "rxftp".  It is available*/
  13. /*  on the internet from hobbes or www.cdrom.com, or from the IBM support*/
  14. /*  bulletin boards. */
  15.  
  16. /*  Written by Alex Doll (adoll@fdva.com) to automate maintenance of the*/
  17. /*  Canadian Inst of Mine image archive at www.mining.ubc.ca/images (plug, plug)*/
  18. /*  This software is free, so you get what you pay for.  There are no guarentees*/
  19. /*  that it will work for you, nor will the author or distributor be liable for*/
  20. /*  any damage that it does to your system.*/
  21. /* */
  22. /*  Hint for Windows users... here's a quick way to get rid of all those */
  23. /*  Windows based system crashes:  */              
  24. /*    type 'format c: /s' from the command line, and you'll never see */
  25. /*  windows crash your system again! */
  26.  
  27.  
  28. parse arg LocalDir RemotePath LoginID LoginPassword
  29. /* parse the command line into a local directory and a remote server and directory, */
  30. /* and login ID and password */
  31.  
  32. if RemotePath="" then do
  33.         say ""        
  34.         say "SpewNew.cmd usage:"
  35.         say "  SPEWNEW \LOCALDIR ftp.remote.ca/pub/remote [loginID] [password]"
  36.         say ""
  37.         say "where '\LOCALDIR' is the local directory root to begin searching down from"
  38.         say "      'ftp.remote.ca' is the ftp server to reach"
  39.         say "      '/pub/remote' is the remote directory root on the remote server"
  40.         say "      [loginID] (optional) the login ID to use entering the FTP server"
  41.         say "      [password] (optional) the password to use entering the FTP server"
  42.         exit -1
  43. end 
  44.  
  45. /* parse the RemotePath (from above) to obtain an FTP server name (that we'll */
  46. /* log into) and a path name (that we'll "cd" to) */
  47. parse value RemotePath with RemoteHost"/"RemotePath
  48.           
  49. if LoginID="" then do
  50.         LoginID="anonymous"
  51.         say "attempting anonymous FTP login.  Some FTP machines may not allow"
  52.         say "anonymous logins."
  53. end /*if*/
  54. if LoginPassword="" then LoginPassword="SpewNew.Rexx.Script@somebodys.os2.machine"
  55.  
  56. say "Attempting to attach FTP functions from rxFTP.DLL file"
  57.    rc = RxFuncAdd("FtpLoadFuncs","rxFtp","FtpLoadFuncs")
  58. if rc<>0 then do
  59.         say "ERROR "rc" ##### UNABLE TO LOAD rxFtp.dll! #####"
  60.         say "You did install the rexx ftp functions from the IBM EWS package, didn't you?"
  61.         exit -1
  62. end /*if*/                                            
  63.    rc = FtpLoadFuncs()
  64.  
  65. /*  Try logging in and checking the directory on REMOTE */
  66. say "Attempting to connect to "RemoteHost
  67. rc=FtpSetUser( RemoteHost, LoginID, LoginPassword)
  68. if rc=-1 then do
  69.         say "****ERROR**** "FtpErrNo
  70.         exit -1
  71. end /*if*/
  72. say "Changing to /"RemotePath
  73. rc=FtpChDir( "/"RemotePath)
  74. if rc=-1 then do
  75.         say "!!!!ERROR!!!! "FtpErrNo
  76.         exit -1                                
  77. end /*if*/
  78.  
  79. /*  OK, if I get this far, then I'm logged in and ready to go to work. */
  80. /*  The first thing to do is build a list of the files on LOCAL that need */
  81. /*  to be spewed over to the remote machine. */                        
  82. LocalPath=Directory(LocalDir)'\'
  83. say "Useing "localPath" as local directory"
  84. 'dir /b /s /aa *.* > SpewTemp.txt'                              
  85. RC=stream( 'SpewTemp.txt', 'c', 'close')
  86.  
  87. /*  Setting binary transfer - I'm too lazy to check for ascii files! */
  88. rc=FtpSetBinary( "Binary")
  89.  
  90. /*  Transfer each of the file names contained in SPEWTEMP.TXT */
  91. do while Lines('SpewTemp.txt')
  92.         aVictim=LineIn('SpewTemp.txt')
  93.         /* double check that the directory is correct */
  94.         if (TRANSLATE(left(aVictim,length(localPath)))=TRANSLATE(localPath)) then do
  95.                 aVictim=right(aVictim, length(aVictim)-length(localPath))
  96.                 RemoteVictim=Translate( aVictim, "/", "\")
  97.                 say "Transferring file "RemoteVictim
  98.                 rc=FtpPut(aVictim, RemoteVictim)
  99.                 if FtpErrNo<>0 then say "!!!!ERROR!!!! "FtpErrNo
  100.                 else 
  101. '@attrib -a 'aVictim
  102.         end
  103.         else
  104.                 say "found ineligible file : "aVictim
  105. end /* do */
  106.  
  107. /*  All files transferred!  Log off and shut everything down  */
  108. say "all done.  Cleaning up"
  109. RC=stream( 'SpewTemp.txt', 'c', 'close')
  110. 'erase SpewTemp.txt'
  111. /*call FtpLogoff()*/
  112. rc=FtpDropFuncs()
  113.