/* NEWHOBBE.CMD
Get description files from /incoming on hobbes.nmsu.edu 
By Dirk Terrell
This code is hereby entered into the public domain.

If browsing this file on the WWW, save it to your local hard
drive with a .CMD extension.  If browsing this file in an
off-line version of OS/2 e-Zine!, just rename the file
hobbeget.txt to hobbeget.cmd */

rc = RxFuncAdd("FtpLoadFuncs","RxFtp","FtpLoadFuncs") /* Load the FTP library */
rc = FtpLoadFuncs()
/* ftp://software.watson.ibm.com/pub/os2/ews/rxftp.zip */
rc = rxfuncadd('SysLoadFuncs','RexxUtil','SysLoadFuncs') /* Load the system utilities */
rc = sysloadfuncs()

Site="hobbes.nmsu.edu"               /* FTP site */
RemoteDir="incoming"                 /* Directory on FTP site */
LocalDir="d:\network\rxftp"          /* Directory to place files in on local machine */
TempFile="newhobbe.txt"              /* The temporary file for the results */
User="anonymous"                     /* Login user ID */
Pass="terrell@gnv.fdt.net"           /* Password, make it your email address */
FileType="Ascii"                     /* We'll be transferring text files */
OldDir=Directory(LocalDir)           /* Change to specified directory */
Say OldDir
if FTPSetUser(Site,User,Pass) then do  /* Successful login to site */
      rc=FTPChDir(RemoteDir)           /* Set the remote directory */
      rc=FTPLs("*.txt",DirList.)       /* Get a listing of files matching *.txt */
      Do i=1 to DirList.0              /* Store the retrieved file names */
         FileList.i=DirList.i
      End
      FileList.0=DirList.0             /* FileList.0 holds the number of files */
      rc=FTPLs("*.TXT",DirList.)       /* Get a listing of files matching *.TXT */
      Do i=1 to DirList.0              /* Store those file names */
         k=i+FileList.0
         FileList.k=DirList.i
      End
      FileList.0=k
      rc=SysFileDelete(TempFile)       /* Delete the temporary file if it exists */
      Do i=1 to FileList.0             /* Loop over all files */
         Test=Translate(FileList.i)    /* Convert filename to uppercase */
         If Test="00INDEX.TXT" | Test="00INDEXD.TXT" then       /* If the file is an index ... */
            Say "Skipping" FileList.i "file" i "of" FileList.0  /*   then skip it */
         else                                                   /* Otherwise do the following */
            Do
               Say "Getting" FileList.i "file" i "of" FileList.0  /* Keep user informed */
               rc=FtpGet(FileList.i,FileList.i,FileType)          /* Get the file */
               rc=Lineout(TempFile," ")                     /* Separator */
               rc=Lineout(TempFile,"*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_")
               rc=Lineout(TempFile,FileList.i)              /* Write file name */
               rc=Lineout(TempFile)                         /* Close the temp. file */
               "@copy" TempFile||"+"||FileList.i "1>nul 2>nul"    /* Append file to temp. file */
               rc=SysFileDelete(FileList.i)                       /* Delete the file */
            End
      end /* do */
      rc=FtpLogOff()                   /* Log off the FTP site */
   End
Else                                   /* Couldn't get logged in */
   Do
      Say "Could not log on to" Site
      Exit
   End
rc=Directory(OldDir)                   /* Change back to original directory */
Exit
