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)
{
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);
}
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
{
log.Info("Creating FTP-via-SOCKS5 client");
ProFTPClient ftp = new ProFTPClient();
log.Info("Setting FTP server address");
ftp.RemoteHost = remoteHost;
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;
log.Info("Connecting to server " + remoteHost);
ftp.Connect();
log.Info("Logging in with username=" + user + " and password=" + password);
ftp.Login(user, password);
log.Info("Setting up passive, ASCII transfers");
ftp.TransferType = FTPTransferType.ASCII;
ftp.ConnectMode = FTPConnectMode.PASV;
log.Info("Directory before put:");
foreach (string fileName in ftp.Dir(".", true))
log.Info(fileName);
log.Info("Putting " + filename + " to server");
ftp.Put(filename, Path.GetFileName(filename));
log.Info("Directory after put:");
foreach (string fileName in ftp.Dir(".", true))
log.Info(fileName);
log.Info("Getting " + Path.GetFileName(filename) + " from server and saving as " + filename + ".copy");
ftp.Get(filename + ".copy", Path.GetFileName(filename));
log.Info("Deleting " + Path.GetFileName(filename));
ftp.Delete(Path.GetFileName(filename));
log.Info("Directory after delete:");
foreach (string fileName in ftp.Dir(".", true))
log.Info(fileName);
log.Info("Quitting client");
ftp.Quit();
}
catch (Exception e)
{
log.Error("Caught exception " + e.GetType().FullName + " " + e.Message, e);
}
}
}