Unreviewed Code - 4gl-based FTP DocumentationPurpose : Monitors an FTP server for incoming files and processes them. Syntax : Description : For the full FTP specification look for RFC959 on http://www.faqs.org This code should be considered as still in development, as such it has been unit tested only. It was not written to be a generic solution. It is heavily based upon the example smtp process available from the Porgress Knowledge base. Use this software at your own risk! Jason Howells 12/07/2001 Author(s) : Jason Howells Created : 04/06/2001 Notes : Some FTP terms are used throughout: PI = Protocol Interpreter DTP = Data Transfer Process An FTP Session consists of the following components Client Server | | PI -------Port 21---------PI | | | | DTP-------Port xxx-------DTP | | Theory ------ Commands travel across port 21, data is transferred across an additional data transfer port. Normally the FTP client process(this process) sets up a server for the DTP and waits for the server process to contact it. There is however a slightly easier way that is also preferable when working through a firewall, Passive mode. Passive mode revereses the process stated above. When the client contacts the server process it issues as PASV command to invoke passive mode. The reply to the PASV command is a string that contains the host and a port address for the DTP on the server. In this way we only have to connect a client socket to the server. This process is repeated for each file transfer. The FTP specification states that control of the data connection (DTP) resides wholly with the server process. However during my testing I found it necessary to close the data connection from the client side before quiting the FTP session. Practice -------- This program functions as follows: 1. Connects to the FTP server on port 21 and recieves a response. 2. Logs in using the gievn user name and password. 3. Sets the transfer type to I (to avoid CRLF's getting appended to the end of every sodding line!) 4. Makes a list of all the xml files present. 5. Works through the list getting one file at a time and streaming it into a memory pointer. 6. This memory pointer is then passed to the Xload function that parses the XML document. 7. Once the document is parsed and loaded into the database, the remote file is then moved into a different directory for archiving purposes. 8. The next file is then processed. 9. When the file list is empty, the program tries to retrive another list if the response is '550 No such file or directory', then there are no xml files to retrieve so the process quits and control returns to the main block in this procedure. 10. The program then pauses before beginning the cycle again. FTP Commands Used (RFC959 contains the full explanation) Command Description ------- ------------------------------------------------------------------------ USER Specify username for login PASS Specify password for login RNFR Rename from... name of file to rename RNTO Rename to... new name of file NOOP Does nothing... returns OK, used here to trip the event processing RETR Retrieve... gets the named file NLST Name List... gets a simple list of files for the specifed directory. QUIT Go on guess...[Download xloader.zip] (12kb) [Return to Unreviewed Code Section] [Return to Main Download Page] |
|