Socks4Client.cs

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

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

public class Socks4Client
{
        public static void Main(string[] args)
        {
                // we want remote remoteHost, user name and password
                if (args.Length < 6)
                {
                        Console.WriteLine("Usage: Socks4Client remote-host username password filename proxy-server proxy-user");
                        Environment.Exit(1);
                }

                // assign args to make it clear
                string remoteHost = args[0];
                string user = args[1];
                string password = args[2];
                string filename = args[3];
                string proxyServer = args[4];
                string proxyUser = args[5];

                Logger log = Logger.GetLogger(typeof(Socks4Client));
                Logger.CurrentLevel = Level.INFO;

                try
                {                       
                        // create client
                        log.Info("Creating FTP-via-SOCKS4 client");
                        ProFTPClient ftp = new ProFTPClient();

                        log.Info("Setting FTP server address");
                        ftp.RemoteHost = remoteHost;

                        // set up SOCKS4 context
                        log.Info("Setting SOCKS4 context");
                        ftp.SocksContext = new Socks4Context(proxyServer, proxyUser, true);

                        // connect to the server
                        log.Info("Connecting to server " + remoteHost);
                        ftp.Connect();

                        // log in
                        log.Info("Logging in with username=" + user + " and password=" + password);
                        ftp.Login(user, password);
                                
                        // set up passive ASCII transfers
                        log.Info("Setting up passive, ASCII transfers");
                        ftp.TransferType = FTPTransferType.ASCII;
                        ftp.ConnectMode = FTPConnectMode.PASV;
                                
                        // test that dir() works in full mode
                        log.Info("Directory before put:");
                        foreach (string fileName in ftp.Dir(".", true))
                                log.Info(fileName);
            
                        // copy file to server
                        log.Info("Putting " + filename + " to server");
                        ftp.Put(filename, Path.GetFileName(filename));
                                
                        // test that dir() works in full mode
                        log.Info("Directory after put:");
                        foreach (string fileName in ftp.Dir(".", true))
                                log.Info(fileName);
            
                        // 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:");
                        foreach (string fileName in ftp.Dir(".", true))
                                log.Info(fileName);
            
                        // Shut down client
                        log.Info("Quitting client");
                }
                catch (Exception e)
                {
                        log.Error("Caught exception " + e.GetType().FullName + " " + e.Message, e);
                }
        }
}

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