ImplicitClient.cs

// edtFTPnet/PRO Example 4
// 
// Copyright (C) 2004 Enterprise Distributed Technologies Ltd
// 
// www.enterprisedt.com

using System;
using System.IO;
using EnterpriseDT.Util.Debug;
using EnterpriseDT.Net.Ftp;
using EnterpriseDT.Net.Ftp.Pro;

public class ImplicitClient 
{
    public static void Main(string[] args) {

        // we want remote host, user name and password
        if (args.Length < 4) {
                System.Console.Out.WriteLine(
                        "Usage: ImplicitClient remote-host username password filename");
                System.Console.Out.WriteLine("See readme.html for instructions.");
                System.Environment.Exit(1);
        }
        
        // extract command-line arguments
        string host = args[0];
        string username = args[1];
        string password = args[2];
        string filename = args[3];
        
        // set up logger so that we get some output
        Logger log = Logger.GetLogger(typeof(ImplicitClient));
        Logger.CurrentLevel = Level.INFO;
        
        try {
            // create client
            log.Info("Creating FTPS (implicit) client");
                        ProFTPClient ftp = new ProFTPClient();
                        ftp.RemoteHost = host;
            ftp.IsImplicitFTPS = true;
            ftp.ServerCompatibility = ProFTPClient.CompatibilityFlags.DisableDataSSLClosure;
                        
                        // NOTE: The DisableControlSSLClosure & DisableDataSSLClosure flags
            // are included in this example for the sake of compatibility with
                        // as wide a range of servers as possible. If possible it should be 
                        // avoided as it opens the possibility of truncation attacks (
                        // i.e. attacks where data is compromised through premature 
                        // disconnection).
            
            // turn off server validation
            log.Info("Turning off server validation");
            ftp.ServerValidation = ProFTPClient.ServerValidationType.None;
            
            // connect to the server
            log.Info("Connecting to server " + host);
            ftp.Connect();
            
            // switch to secure 
            ftp.Auth();
            
            // log in
            log.Info(
                "Logging in with username="
                        + username);
            ftp.Login(username, password);
            
            // set up passive ASCII transfers
            log.Info("Setting up passive, ASCII transfers");
            ftp.ConnectMode = FTPConnectMode.PASV;
            ftp.TransferType = FTPTransferType.ASCII;
            
            // get directory and display it
            log.Info("Directory before put:");
            string[] files = ftp.Dir(".", true);
            ShowFiles(log, files);
            
            // copy file to server
            log.Info("Putting " + filename + " to server");
            ftp.Put(filename, Path.GetFileName(filename));
            
            // get directory and print it to console
            log.Info("Directory after put:");
            files = ftp.Dir(".", true);
            ShowFiles(log, files);
            
            // copy file from server
            log.Info(
                "Getting "
                        + Path.GetFileName(filename)
                        + " from server and saving as "
                        + filename
                        + ".copy");
            ftp.Get(filename + ".copy", Path.GetFileName(filename));
            
            // delete file from server
            log.Info("Deleting " + Path.GetFileName(filename));
            ftp.Delete(Path.GetFileName(filename));
            
            // get directory and print it to console
            log.Info("Directory after delete:");
            files = ftp.Dir("", true);
            ShowFiles(log, files);
            
            // Shut down client
            log.Info("Quitting client");
            ftp.Quit();
            
            log.Info("Test complete");
        } 
        catch (Exception e) {
                        log.Error("Caught exception " + e.GetType().FullName + " " + e.Message, e);
                }
        }

    private static void ShowFiles(Logger log, string[] files) {
        if (files.Length == 0)
            log.Info("  no files");
        else
            for (int i = 0; i < files.Length; i++)
                log.Info("  " + files[i]);
    }
}

Generated on Wed Jan 26 19:05:03 2005 for NonvalidatingClient by  doxygen 1.4.1