using System;
using System.IO;
using EnterpriseDT.Util.Debug;
using EnterpriseDT.Net.Ftp;
using EnterpriseDT.Net.Ftp.Pro;
public class NonvalidatingClient
{
public static void Main(string[] args)
{
if (args.Length < 4) {
System.Console.Out.WriteLine(
"Usage: NonvalidatingClient remote-host username password filename");
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];
Logger log = Logger.GetLogger(typeof(NonvalidatingClient));
Logger.CurrentLevel = Level.INFO;
try {
log.Info("Creating FTPS (explicit) client");
ProFTPClient ftp = new ProFTPClient();
ftp.RemoteHost = host;
ftp.ServerCompatibility = ProFTPClient.CompatibilityFlags.DisableDataSSLClosure;
log.Info("Turning off server validation");
ftp.ServerValidation = ProFTPClient.ServerValidationType.None;
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
+ " and password="
+ password);
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("Example 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]);
}
}