Skip to content

Instantly share code, notes, and snippets.

@PaulStovell
Created February 19, 2014 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulStovell/22a4bca7639d64ca24a5 to your computer and use it in GitHub Desktop.
Save PaulStovell/22a4bca7639d64ca24a5 to your computer and use it in GitHub Desktop.
using System.Diagnostics;
using EnterpriseDT.Net.Ftp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnterpriseDT.Net.Ftp.Ssl;
namespace FtpDemo
{
class Program
{
static void Main(string[] args)
{
var ftpConnection = new SecureFTPConnection
{
LicenseOwner = "OctopusDeploy",
LicenseKey = "PUT_YOUR_LICENSE_KEY_HERE",
Protocol = FileTransferProtocol.FTPSExplicit,
ServerAddress = "waws-prod-ch1-001.ftp.azurewebsites.windows.net",
UserName = "octodemo3\\octoftp",
Password = "Password01!",
AutoLogin = true,
AutoSecure = true,
ServerValidation = SecureFTPServerValidationType.None,
RetryCount = 20,
Timeout = 1000 * 60 * 10,
SynchronizePassiveConnections = true,
TransferBufferSize = 1024,
CipherSuites = SSLFTPCipherSuite.SECURE_CIPHERS,
RetryDelay = 1000
};
SecureFTPConnection.LogFile = "C:\\tmp\\Ftp.log.txt";
SecureFTPConnection.LogToConsole = true;
long b = 0;
ftpConnection.BytesTransferred += (sender, eventArgs) =>
{
b += eventArgs.ByteCount;
Console.Title = b.ToString("n0");
};
ftpConnection.ParallelTransferMode = false;
ftpConnection.TransferNotifyListings = true;
ftpConnection.ConnectMode = FTPConnectMode.PASV;
ftpConnection.Synchronized += OnSynchronized;
ftpConnection.Error += OnError;
ftpConnection.CommandSent += OnCommandSent;
ftpConnection.Connecting += OnConnecting;
ftpConnection.Connected += OnConnected;
ftpConnection.Closed += OnClosed;
ftpConnection.Connect();
if (ftpConnection.WelcomeMessage != null)
{
var message = string.Join(Environment.NewLine, ftpConnection.WelcomeMessage);
Console.WriteLine("Welcome message: {0}", message);
}
var rules = new FTPSyncRules
{
Direction = TransferDirection.UPLOAD,
IgnoreCase = true,
IncludeSubdirectories = true,
DeleteIfSourceAbsent = true,
FilterType = FTPFilterType.Callback,
FilterCallback = FilterCallback
};
var watch = Stopwatch.StartNew();
var results = ftpConnection.Synchronize(@"C:\tmp\OldTentacle", "/site/wwwroot/d", rules);
Console.WriteLine("Time taken: " + watch.Elapsed.TotalSeconds +" sec");
Console.WriteLine("Failures: " + results.FailureCount);
Console.WriteLine("Done...");
Console.ReadLine();
}
private static void OnError(object sender, FTPErrorEventArgs e)
{
Console.WriteLine("Error : " + e.Exception);
}
static bool FilterCallback(FTPFile file)
{
var name = Path.GetFileName(file.Name);
return true;
}
static void OnConnecting(object sender, FTPConnectionEventArgs ftpConnectionEventArgs)
{
Console.WriteLine("Connecting...");
}
static void OnConnected(object sender, FTPConnectionEventArgs e)
{
if (e.Exception != null)
{
Console.WriteLine("Unable to connect: " + e.Exception.Message);
}
else
{
Console.WriteLine("Connected");
}
}
static void OnCommandSent(object sender, FTPMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
static void OnSynchronized(object sender, FTPSyncEventArgs e)
{
Console.WriteLine("Synchronize complete");
var results = e.Results;
if (results != null)
{
Console.WriteLine("Total operations: " + results.TotalCount);
}
}
static void OnClosed(object sender, FTPConnectionEventArgs e)
{
Console.WriteLine("Connection closed");
}
}
}
INFO [FTPConnection] 19 Feb 2014 21:55:14.470 : OS: 6.2.9200.0, CLR: 4.0.30319.34011, DLL: 8.5.0.20
INFO [FTPConnection] 19 Feb 2014 21:55:14.471 : Built: 4-Jul-2013 14:12:58 EST
INFO [LicenseProperties] 19 Feb 2014 21:55:14.489 : Licence expiry date: 31/12/9999
INFO [LicenseProperties] 19 Feb 2014 21:55:14.490 : Production license
Connecting...
INFO [LicenseProperties] 19 Feb 2014 21:55:14.498 : Licence expiry date: 31/12/9999
INFO [LicenseProperties] 19 Feb 2014 21:55:14.498 : Production license
INFO [SSLFTPSocket] 19 Feb 2014 21:55:14.818 : Connecting to 168.62.232.14:21 with timeout 600000 ms
INFO [FTPControlSocket] 19 Feb 2014 21:55:15.256 : Command encoding=System.Text.SBCSCodePageEncoding
---> AUTH TLS
---> PBSZ 0
---> PROT P
---> USER octodemo3\octoftp
---> PASS ********
Connected
INFO [FTPConnection] 19 Feb 2014 21:55:18.413 : FTPConnection.1Auto FEAT disabled
---> TYPE I
---> PWD
INFO [FTPSynchronizer] 19 Feb 2014 21:55:18.942 : FTPConnection.1Synchronize C:\tmp\OldTentacle with /site/wwwroot/d
---> CWD /site/wwwroot/d/
---> CWD /
---> CWD /site/wwwroot/d/
---> PWD
---> SYST
---> PWD
---> PASV
INFO [SSLFTPSocket] 19 Feb 2014 21:55:21.359 : FTPConnection.1Connecting to 168.62.232.14:10085 with timeout 600000 ms
---> LIST
---> CWD Azure
---> PWD
---> PWD
---> PASV
INFO [SSLFTPSocket] 19 Feb 2014 21:55:23.961 : FTPConnection.1Connecting to 168.62.232.14:10090 with timeout 600000 ms
---> LIST
---> CWD /site/wwwroot/d
---> PWD
---> CWD ScriptCS
---> PWD
---> PWD
---> PASV
INFO [SSLFTPSocket] 19 Feb 2014 21:55:27.297 : FTPConnection.1Connecting to 168.62.232.14:10268 with timeout 600000 ms
---> LIST
WARN [SocketController] 19 Feb 2014 21:57:38.019 : FTPConnection.1OnReceive - (An existing connection was forcibly closed by the remote host) - closing
WARN [SocketController] 19 Feb 2014 21:59:46.368 : FTPConnection.1OnReceive - (An existing connection was forcibly closed by the remote host) - closing
ERROR [FTPConnection] 19 Feb 2014 21:59:46.369 : FTPConnection.1ChangeWorkingDirectory error: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1Error event while executing GetFileInfos - notifying Error event-handlers
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1EnterpriseDT.Net.Ftp.FTPException: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.FTPClient.Eg4fhcICnB(Boolean )
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.FTPClient.ChDir(String dir)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.FTPConnection.ChangeWorkingDirectory(String directory)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.ExFTPConnection.ChangeWorkingDirectory(String directory)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.ConnRecursiveOperations.ChangeWorkingDirectory(String directory)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.AbstractRecursiveOperations.DirDetails(String remoteDir, String wildcard)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.AbstractRecursiveOperations.DirDetails(String remoteDir, String wildcard)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.371 : FTPConnection.1 at EnterpriseDT.Net.Ftp.ExFTPConnection.GetFileInfos(String directory, String wildcard, Boolean includeSubdirectories)
Error : EnterpriseDT.Net.Ftp.FTPException: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
at EnterpriseDT.Net.Ftp.FTPClient.Eg4fhcICnB(Boolean )
at EnterpriseDT.Net.Ftp.FTPClient.ChDir(String dir)
at EnterpriseDT.Net.Ftp.FTPConnection.ChangeWorkingDirectory(String directory)
at EnterpriseDT.Net.Ftp.ExFTPConnection.ChangeWorkingDirectory(String directory)
at EnterpriseDT.Net.Ftp.ConnRecursiveOperations.ChangeWorkingDirectory(String directory)
at EnterpriseDT.Net.Ftp.AbstractRecursiveOperations.DirDetails(String remoteDir, String wildcard)
at EnterpriseDT.Net.Ftp.AbstractRecursiveOperations.DirDetails(String remoteDir, String wildcard)
at EnterpriseDT.Net.Ftp.ExFTPConnection.GetFileInfos(String directory, String wildcard, Boolean includeSubdirectories)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.375 : FTPConnection.1Event-handlers notified successfully
INFO [FTPTask] 19 Feb 2014 21:59:46.375 : FTPConnection.1Throwing stored exception: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.376 : FTPConnection.1Error event while executing r1rb4k9V5sa - notifying Error event-handlers
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.376 : FTPConnection.1EnterpriseDT.Net.Ftp.FTPException: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.376 : FTPConnection.1 at EnterpriseDT.Net.Ftp.FTPTask.r4M6UXrqub()
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.376 : FTPConnection.1 at EnterpriseDT.Net.Ftp.FTPTask.get_ReturnValue()
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.376 : FTPConnection.1 at EnterpriseDT.Net.Ftp.ExFTPConnection.EndGetFileInfos(IAsyncResult asyncResult)
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.376 : FTPConnection.1 at YCI9u27a1oMu68GXnaS.OFnVm47SuspJNvpIdPM.SvSb4Hcf2ak(IAsyncResult )
Error : EnterpriseDT.Net.Ftp.FTPException: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
at EnterpriseDT.Net.Ftp.FTPTask.r4M6UXrqub()
at EnterpriseDT.Net.Ftp.FTPTask.get_ReturnValue()
at EnterpriseDT.Net.Ftp.ExFTPConnection.EndGetFileInfos(IAsyncResult asyncResult)
at YCI9u27a1oMu68GXnaS.OFnVm47SuspJNvpIdPM.SvSb4Hcf2ak(IAsyncResult )
ERROR [ExFTPConnection] 19 Feb 2014 21:59:46.382 : FTPConnection.1Event-handlers notified successfully
INFO [FTPTask] 19 Feb 2014 21:59:46.384 : FTPConnection.1Throwing stored exception: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
Unhandled Exception: EnterpriseDT.Net.Ftp.FTPException: The FTP client has not yet connected to the server. The requested action cannot be performed until after a connection has been established.
at EnterpriseDT.Net.Ftp.FTPTask.r4M6UXrqub()
at YCI9u27a1oMu68GXnaS.OFnVm47SuspJNvpIdPM.uoCtiI730uhppJYuAkP.get_ReturnValue()
at YCI9u27a1oMu68GXnaS.OFnVm47SuspJNvpIdPM.LIVb42QLjtN(IAsyncResult )
at YCI9u27a1oMu68GXnaS.OFnVm47SuspJNvpIdPM.r1rb4k9V5sa(FTPSyncRules , String , String )
at EnterpriseDT.Net.Ftp.ExFTPConnection.Synchronize(String localDirectory, String serverDirectory, FTPSyncRules syncRules)
at FtpDemo.Program.Main(String[] args) in c:\Users\Paul\Documents\Visual Studio 2013\Projects\FtpDemo\FtpDemo\Program.cs:line 77
Press any key to continue . . .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment