Example 1: Nonvalidating Client

This example illustrates the use of ProFTPClient in explicit FTPS mode with neither server nor client validation. This is not recommended usage since there is no way for either party to ensure that the other party is who it claims to be, but it serves well to illustrate basic usage.

The example performs the following operations:

  1. Switches off server validation.
  2. Connects to the server in plain FTP mode.
  3. Switches to explicit FTPS mode.
  4. Logs in.
  5. Lists directory contents.
  6. Puts a file to the server.
  7. Lists directory contents.
  8. Gets the same file back from the server.
  9. Lists directory contents.
  10. Disconnects.

You can view the source-code here.

INSTRUCTIONS:

  1. Make sure you have a working FTP server with FTPS enabled.
    You may like to use EDT's free FTP/FTPS server, edtFTPD, for this purpose.
    To test that the server is set up correctly, EDT recommends the FTP/FTPS client FileZilla.
  2. Open a console window.
  3. Change to the examples/Ex1_NonvalidatingClient directory.
  4. Make sure that the C# compiler, csc.exe, is in your PATH.
  5. Run the example by:
    run hostname username password filename
    
    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.
    filename is the name of the ASCII file in the current dir you wish to transfer
  6. Verify that the output looks something like this (there will be additional lines of debug):
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:45.927 : Creating FTPS (explicit) client
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:45.947 : Turning off server validation
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:45.947 : Connecting to server LOCALHOST
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:47.189 : Switching to FTPS (explicit mode)
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:47.569 : Logging in with username=test and password=test
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:47.599 : Setting up passive, ASCII transfers
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:47.609 : Directory before put:
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:47.970 :   no files
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:47.970 : Putting NonvalidatingClient.exe to server
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:48.270 : Directory after put:
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:48.491 :   -rw-r--r--   1 SYSTEM   None        16238 Jan 26 06:40 NonvalidatingClient.exe
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:48.491 : Getting NonvalidatingClient.exe from server and saving as NonvalidatingClient.exe.copy
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:48.811 : Deleting NonvalidatingClient.exe
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:48.821 : Directory after delete:
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:49.172 :   no files
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:49.172 : Quitting client
    INFO [NonvalidatingClient] 26 Jan 2005 16:40:49.182 : Example complete
    There should now also be a file called YourFilename.copy in the local directory.