/* An example of using the RexxInet functions to list a directory * on an Ftp site. */ /* ========================= STEP 1 ========================== * Just some preliminary settings to make our programming * easier. */ /* So that we don't need the CALL keyword. */ OPTIONS "C_CALL" /* Some OS functions deal with 32-bit addresses so we need * 10 digits to prevent dealing with exponential form. */ NUMERIC DIGITS 10 /* ========================= STEP 2 ========================== * Load RexxInet functions. Set up error handling for RexxInet. * Have it raise ERROR condition. This is done once at the * start of our script. */ /* Load REXXINET.DLL and register all its functions. */ DO RxFuncAdd("rexxinet") /* Here you would RxFuncAdd() or FuncDef() any additional DLLs you use. */ /* If REXXINET fails to load and register its functions, we do the following. */ CATCH FAILURE /* Display an error message box, and end the script. */ CONDITION("M") RETURN END InetErr = "ERROR" InetHeading = 1 /* ========================= STEP 3 ========================== * Make sure we're connected to the internet (if a dial-up * account), and initialize RexxInet. */ DO /* Make sure we're connected to the internet. If not, * automatically connect the default account. */ InetDial("ONLINE") /* Initialize REXXINET. We tell WinINet that our script name is "My test" */ InetOpen(, , "My test") /* Let's CATCH ERROR so we don't have to error check * any of the above calls to RexxINet functions. Yay! */ CATCH ERROR CONDITION('M') RETURN END /* ========================= STEP 4 ========================== * List the contents of a directory. */ /* Here's the FTP server hosting the files/dirs I want to list. * I could pass this directly to InetConnect if desired. */ myFtpSite = "ftp.microsoft.com" /* Connect to the server, and save the handle in "MyFtpHandle". */ InetConnect("MyFtpHandle", myFtpSite, "FTP") /* Set the current directory to "peropsys". */ InetDir("peropsys") /* Get the next file/dir and store information in the variable * "dirInfo". Note: If there are no more matching files, then * "DONE" is returned. NOTE: No condition is raised in that * event, even if we've set InetErr to do so for errors. */ DO WHILE InetMatchName("dirInfo") == "" /* Display the name. */ CHAROUT(, dirInfo) /* If it's a directory, display . */ flag = BIT(dirInfo.2, 4) IF flag THEN SAY " " ELSE SAY END /* If desired, you can now enumerate another dir from the same * FTP server by doing another InetMatchName() on that directory * name. You should use InetDir to set to that directory. If you * wish to enumerate files/dirs on a different server, then you * should also do a InetClose("MyFtpHandle") first. */ /* Done */ RETURN /* ================ Error handling and cleanup ================ */ CATCH ERROR CONDITION('M') FINALLY /* Terminate use of RexxInet and disconnect from the internet. * NOTE: If our main script ends without doing this, then * RexxInet implicitly does this for us. */ InetClose()