using System;
using System.IO;
using EnterpriseDT.Util.Debug;
using EnterpriseDT.Net.Ftp;
using EnterpriseDT.Net.Ftp.Pro;
public class ServerValidatingClient
{
public static void Main(string[] args)
{
if (args.Length < 4) {
System.Console.Out.WriteLine("Usage: ServerValidatingClient remote-host username password filename (hostname-checking)");
System.Console.Out.WriteLine("See readme.html for instructions.");
System.Environment.Exit(1);
}
string host = args[0];
string username = args[1];
string password = args[2];
string filename = args[3];
bool enableHostNameChecking = args.Length<5 || args[4].ToLower().Equals("on");
Logger log = Logger.GetLogger(typeof(ServerValidatingClient));
Logger.CurrentLevel = Level.INFO;
try
{
log.Info("Creating FTPS (explicit) client");
ProFTPClient ftp = new ProFTPClient();
ftp.RemoteHost = host;
ftp.ServerCompatibility = ProFTPClient.CompatibilityFlags.DisableDataSSLClosure;
if (!enableHostNameChecking)
{
log.Info("Disable host-name checking (only recommended when testing)");
ftp.ServerValidation = ProFTPClient.ServerValidationType.AutomaticNoNameCheck;
}
else
{
log.Info("Host-name checking enabled");
ftp.ServerValidation = ProFTPClient.ServerValidationType.Automatic;
}
log.Info("Connecting to server " + host);
ftp.Connect();
log.Info("Switching to FTPS (explicit mode)");
ftp.Auth(ProFTPClient.SecurityMechanism.TLS);
log.Info(
"Logging in with username="
+ username);
ftp.Login(username, password);
log.Info("Setting up passive, ASCII transfers");
ftp.ConnectMode = FTPConnectMode.PASV;
ftp.TransferType = FTPTransferType.ASCII;
log.Info("Directory before put:");
string[] files = ftp.Dir(".", true);
ShowFiles(log, files);
log.Info("Putting " + filename + " to server");
ftp.Put(filename, Path.GetFileName(filename));
log.Info("Directory after put:");
files = ftp.Dir(".", true);
ShowFiles(log, files);
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:");
files = ftp.Dir("", true);
ShowFiles(log, files);
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]);
}
}