home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ftpme.zip / ftpme.cmd
OS/2 REXX Batch file  |  1997-08-28  |  6KB  |  229 lines

  1. /***
  2.  * FTP mirroring tool, Aug 28, 1997
  3.  *
  4.  *  Usage:  Place ftpme.cmd in a directory structure that you would like to
  5.  *          send.  When ftpme.cmd is executed, it will send the entire contents
  6.  *          of the directory that it was placed in, including all subdirectories
  7.  *          and the files contained within them, to the destination specified
  8.  *          on the command line.
  9.  *
  10.  *          ftpme host userid password send-directory
  11.  *          where host - the destination machine
  12.  *                userid - kind of self explanatory!
  13.  *                password - kind of self explanatory!
  14.  *                send-directory - the directory to send the files to.  If you
  15.  *                   are sending to the default directory for your login, just
  16.  *                   enter a . ( period ) to signinfy the current directory.
  17.  *
  18.  * This has been released as freeware, so please use as you see fit, all that I
  19.  * ask in return is a message letting me know that you are using my software. I
  20.  * can be reached at starfield@stealthmail.com
  21.  *
  22.  * I intend to extend this little script to include the retrieval of an entire
  23.  * directory structure of an FTP site.  I also intend to first add a text mode
  24.  * interface, followed later by a GUI.  Unfortunately, I do not know when I
  25.  * will be doing this, as I am going back to school in 1 week and will not have
  26.  * much time to
  27.  *
  28.  *    === DISCLAIMER ===
  29.  *
  30.  * I allow you to use and distribute FTPME freely under the condition that I
  31.  * am in no way responsible for any damage or loss you may suffer.
  32.  *
  33.  * Michael S. Chajkowski, starfield@stealthmail.com
  34.  ***/
  35.  
  36. parse arg Host UserID Password RootDir
  37.  
  38. if testCmdLn( Host, UserID, Password, RootDir ) then
  39.    return 1
  40.  
  41. if LoadRexxUtil() then
  42.    return 1
  43.  
  44. if loadrxFTP() then
  45.    return 1
  46.  
  47. call Init_Logon
  48.  
  49. if SysFileTree( '*', '_dir', 'DS' ) then do
  50.    say( "error: could not read the local directory" )
  51.    call logout
  52.    return 1
  53.    end
  54.  
  55. if ftpCHDir( RootDir ) = 0 then do
  56.    call filePut
  57.    do i = 1 to _dir.0
  58.       parse var _dir.i x '\' y '\' path
  59.       if navDir( path ) = 1 then do
  60.          say( "error: could not complete process" )
  61.          call logout
  62.          return 1
  63.          end
  64.       end
  65.    end
  66. else do
  67.    say( "error: invalid FTP directory, please correct and try again x" )
  68.    call logout
  69.    return 1
  70.    end
  71.  
  72. rc = ftpDelete( 'ftpme.cmd' )
  73.  
  74. call logout
  75.  
  76. return 0
  77.  
  78.  
  79. /***
  80.  * Navigate through and create directory structure
  81.  * on remote FTP site.  Mirror FTP cd on local machine
  82.  * and PUT files when deepest dir level achieved
  83.  ***/
  84. navDir: PROCEDURE
  85.  
  86.    arg path
  87.  
  88.    upDir = '..'
  89.  
  90.    if pos( '\', path ) > 0 then do  /* check if at deepest dir level */
  91.       parse var path root '\' path  /* if not, parse for the current dir and subsequent dirs */
  92.       if ftpCHDir( root ) = 0 then do   /* check for valid FTP cd, if valid keep going, if not ... */
  93.          '@cd 'root
  94.          if navDir( path ) = 1 then do
  95.             say( "error: could not complete process" )
  96.             call logout
  97.             return 1
  98.             end
  99.          rc = ftpCHDir( upDir ) /* this directory MUST exist, so no error check */
  100.          '@cd 'upDir
  101.          end
  102.       else do
  103.          say( "error: invalid FTP directory, please correct and try again" )
  104.          call logout
  105.          return 1
  106.          end
  107.       end
  108.    else do
  109.  
  110.       if ftpMKDir( path ) = 0 then      /* check for valid directory creation and navigation */
  111.          if ftpCHDir( path ) = 0 then
  112.             '@cd 'path
  113.          else do
  114.             logout
  115.             return 1
  116.          end
  117.       else do
  118.          logout
  119.          return 1
  120.       end
  121.  
  122.       if filePut() = 1 then do
  123.          say( "error: could not copy files"
  124.          logout
  125.          return 1
  126.          end
  127.  
  128.       rc = ftpCHDir( upDir )
  129.       '@cd 'upDir
  130.       end
  131.  
  132. return 0
  133.  
  134.  
  135. /***
  136.  * Login to the ftp site and set binary mode
  137.  ***/
  138. Init_Logon:                                  /* initialize RXFTP environment */
  139.    say( "Logging into the host system, please wait ..." )
  140.    rc = FtpSetUser( Host, Userid, Password ) /* attach to the remote ftp site */
  141.    rc = FtpSetBinary("b")                    /* set the mode to BINARY */
  142.  
  143.    return
  144.  
  145.  
  146. /***
  147.  * Log off of the FTP server
  148.  ***/
  149. logout:
  150.  
  151.    rc = ftpLogoff()
  152.  
  153.    return
  154.  
  155.  
  156. /***
  157.  * Test the command line for valid number of arguments and
  158.  * for a '?' (denoting the user wants help)
  159.  ***/
  160. testCmdLn: PROCEDURE
  161.  
  162.    parse arg hst, usr, pas, roo
  163.  
  164.    if hst = '' | usr = '' | pas = '' | roo = '' | pos( '?', hst ) > 0 then do
  165.       say( "usage:" )
  166.       say( "ftpme HOST USERNAME PASSWORD FTPDirectory" )
  167.       say( "-- for current FTP dir, use a single period --" )
  168.       return 1
  169.       end
  170.  
  171.    return 0
  172.  
  173.  
  174. /***
  175.  * Load the RexxUtil function library, testing for
  176.  * proper completion of task
  177.  ***/
  178. filePut:
  179.  
  180.    if SysFileTree( '*', '_file', 'F' ) = 0 then /* check for proper file list retrieval */
  181.       do i = 1 to _file.0                       /* strip unnecissary information from the file list */
  182.          parse var _file.i trash ':' trash ':' source
  183.          source = 'd:'source
  184.          dest = right( _file.i, ( length( _file.i ) - lastpos( '\', _file.i )))
  185.          if ftpPut( source, dest ) <> 0 then do
  186.             say( "error: could not PUT the file, make sure you" )
  187.             say( "       have the proper permissions on the FTP server" )
  188.             call logout
  189.             return 1
  190.             end
  191.          end
  192.  
  193.    return 0
  194.  
  195.  
  196. /***
  197.  * Load the RexxUtil function library, testing for
  198.  * proper completion of task
  199.  ***/
  200. LoadRexxUtil: PROCEDURE
  201.    if RxFuncQuery( 'SysLoadFuncs' ) then do
  202.       if rxFuncAdd( 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' ) then do
  203.          say "error: Couldn't load RexxUtil library!"
  204.          return 1
  205.          end
  206.  
  207.       call SysLoadFuncs
  208.       end
  209.  
  210.    return 0
  211.  
  212.  
  213. /***
  214.  * Load the rxFTP function library, testing for
  215.  * proper completion of task
  216.  ***/
  217. LoadrxFTP: PROCEDURE
  218.    if RxFuncQuery( 'FtpLoadFuncs' ) then do
  219.       if rxFuncAdd( 'FtpLoadFuncs', 'rxFTP', 'FtpLoadFuncs' ) then do
  220.          say "error: Couldn't load rxFTP library!"
  221.          return 1
  222.          end
  223.  
  224.       call FtpLoadFuncs
  225.       end
  226.  
  227.    return 0
  228.  
  229.