Socks5Client.cs

// edtFTPnet/PRO Example 6
// 
// 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 Socks5Client
{
        public static void Main(string[] args)
        {
                // we want remote remoteHost, user name and password
                if (args.Length<5 || args.Length==6)
                {
                        Console.Error.WriteLine("Usage: Socks5Client remote-host username password filename " 
                                + "proxy-server [proxy-user proxy-password]");
                        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 = null;
                string proxyPassword = null;
                if (args.Length>=7)
                {
                        proxyUser = args[5];
                        proxyPassword = args[6];
                }

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

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

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

                        // set up SOCKS4 context
                        log.Info("Setting SOCKS5 context");
                        Socks5Context socksContext = new Socks5Context(proxyServer);
                        socksContext.AuthMethods.Add(new Socks5NoAuthMethod());
                        if (proxyUser!=null && proxyPassword!=null)
                                socksContext.AuthMethods.Add(new Socks5UserNamePasswordAuthMethod(proxyUser, proxyPassword));
                        ftp.SocksContext = socksContext;

                        // 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");
                        ftp.Quit();
                }
                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