Example 7: Recursive Operations
This example illustrates the use of the RecursiveOperations class.
It demonstrates (in non-FTPS mode) how a remote directory can be fetched or
deleted, and how a local directory and its contents can be put onto the
FTP server in one operation.
The example performs the following operations:
- Connects to the server in plain FTP mode.
- Fetches the remote directory.
- Logs in.
- Gets the remote directory to a temporary directory.
- Puts the temporary directory back to the server.
- Gets the new remote directory to another temporary directory.
- Deletes the new remote directory.
- Compares the two local temporary directories, and deletes their contents.
- Disconnects.
You can view the source-code here.
INSTRUCTIONS:
-
Make sure you have a working FTP server.
You may like to use EDT's free FTP/FTPS server, edtFTPD, for this purpose.
-
Open a console window.
-
Change to the examples/Ex5_RecursiveOps directory.
-
Run the example by:
run hostname username password remotedir
where
hostname is the address/name of the FTP server.
username is the username of the user account on the FTP server.
password is the password of the user account on the FTP server.
remotedir is the name of the directory on the FTP server that is being fetched.
-
The default logging level is INFO, and the output should look the below. If you wish to
see all the FTP operations, set the level to DEBUG:
INFO [RecursiveOps] 26 Feb 2005 18:57:32.294 : Retrieved remote directory remote to remote_717190735_1
INFO [RecursiveOps] 26 Feb 2005 18:57:32.615 : Put local directory remote_717190735_1 to remote_717190735_1
INFO [RecursiveOps] 26 Feb 2005 18:57:32.905 : Retrieved remote directory remote_717190735_1 to remote_717190735_2
INFO [RecursiveOps] 26 Feb 2005 18:57:32.995 : Deleted remote directory remote_717190735_1
INFO [RecursiveOps] 26 Feb 2005 18:57:33.035 : Directories are identical
Note that the fetched directories are deleted at the completion of this test, as is the new remote
directory.