A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rharrisxtheta/FluentFTP below:

rharrisxtheta/FluentFTP: An FTP and FTPS client for .NET & .NET Standard, optimized for speed. Provides extensive FTP commands, File uploads/downloads, SSL/TLS connections, Automatic directory listing parsing, File hashing/checksums, File permissions/CHMOD, FTP proxies, UTF-8 support, Async/await support and more. Written entirely in C#, with no external dependencies.

FluentFTP is a fully managed FTP and FTPS library for .NET & .NET Standard, optimized for speed. It provides extensive FTP commands, File uploads/downloads, SSL/TLS connections, Automatic directory listing parsing, File hashing/checksums, File permissions/CHMOD, FTP proxies, UTF-8 support, Async/await support and more.

It is written entirely in C#, with no external dependencies. FluentFTP is released under the permissive MIT License, so it can be used in both proprietary and free/open source applications.

Stable binaries are released on NuGet, and contain everything you need to use FTP/FTPS in your .Net/CLR application. For usage see the Example Usage section and the Documentation section below.

FluentFTP works on .NET and .NET Standard/.NET Core.

Platform Binaries Folder Solution .NET 2.0 net20 FluentFTP_NET_VS2012.sln .NET 3.5 net35 FluentFTP_NET_VS2012.sln .NET 4.0 net40 FluentFTP_NET_VS2012.sln .NET 4.5 net45 FluentFTP_NET_VS2012.sln .NET Standard 1.4 netstandard1.4 FluentFTP_Core14_VS2017.sln .NET Standard 1.6 netstandard1.6 FluentFTP_Core16_VS2017.sln .NET Core 5.0 dnxcore50 FluentFTP_Core16_VS2017.sln

FluentFTP is also supported on these platforms: (via .NET Standard)

// create an FTP client
FtpClient client = new FtpClient("123.123.123.123");

// if you don't specify login credentials, we use the "anonymous" user account
client.Credentials = new NetworkCredential("david", "pass123");

// begin connecting to the server
client.Connect();

// get a list of files and directories in the "/htdocs" folder
foreach (FtpListItem item in client.GetListing("/htdocs")) {
	
	// if this is a file
	if (item.Type == FtpFileSystemObjectType.File){
		
		// get the file size
		long size = client.GetFileSize(item.FullName);
		
	}
	
	// get modified date/time of the file or folder
	DateTime time = client.GetModifiedTime(item.FullName);
	
	// calculate a hash for the file on the server side (default algorithm)
	FtpHash hash = client.GetHash(item.FullName);
	
}

// upload a file
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt");

// rename the uploaded file
client.Rename("/htdocs/big.txt", "/htdocs/big2.txt");

// download the file again
client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/big2.txt");

// delete the file
client.DeleteFile("/htdocs/big2.txt");

// delete a folder recursively
client.DeleteDirectory("/htdocs/extras/");

// check if a file exists
if (client.FileExists("/htdocs/big2.txt")){ }

// check if a folder exists
if (client.DirectoryExists("/htdocs/extras/")){ }

// upload a file and retry 3 times before giving up
client.RetryAttempts = 3;
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt", FtpExists.Overwrite, false, FtpVerify.Retry);

// disconnect! good bye!
client.Disconnect();

Complete API documentation for the FtpClient class, which handles all FTP/FTPS functionality.

Note: All methods support synchronous and asynchronous versions. Simply add the "Async" postfix to a method for async/await syntax in .NET 4.5+, or add the "Begin"/"End" prefix to a method for .NET 4.0 and below.

High-level API:

Low-level API:

Working directory (relative paths are relative to this directory):

Directories:

Files:

Standard commands supported by most servers

Only supported by UNIX FTP servers which have the CHMOD extension installed and enabled.

(Note: The high-level file transfer API supports automatic hashing after upload/download).

Standard commands supported by most servers

Non-standard commands supported by certain servers only. Learn more

FTP Protocol

File Listings

File Transfer

Active FTP

Timeouts

Socket Settings

Please import FluentFTP to use these extension methods, or access them directly under the FtpExtensions class.

Please access these static methods directly under the FtpClient class.

Please see these FAQ entries for help on logging & debugging.

.NET Standard only

.NET Framework only

Mapping table documenting supported FTP commands and the corresponding API..

Connection commands

Command API Description USER, PASS Credentials Login with username & password QUIT Disconnect() Disconnect PASV, EPSV, EPRT DataConnectionType Passive & Active FTP modes FEAT HasFeature() Get the features supported by server SYST GetSystem() Get the server system type OPTS UTF8 ON Encoding Enables UTF-8 filenames OPTS UTF8 OFF Encoding, DisableUTF8() Disables UTF-8 filenames AUTH TLS EncryptionMode Switch to TLS/FTPS PBSZ, PROT EncryptionMode and
DataConnectionEncryption Configure TLS/FTPS connection CCC PlainTextEncryption Switch to plaintext FTP PRET Automatic Pre-transfer file information TYPE A UploadDataType and
DownloadDataType Transfer data in ASCII TYPE I UploadDataType and
DownloadDataType Transfer data in Binary

File Management commands

Command API Description MLSD GetListing() Get directory machine list LIST GetListing() with FtpListOption.ForceList Get directory file list NLST GetNameListing()
GetListing() with FtpListOption.ForceNameList Get directory name list MLST GetObjectInfo() Get file information DELE DeleteFile() Delete a file MKD CreateDirectory() Create a directory RMD DeleteDirectory() Delete a directory CWD SetWorkingDirectory() Change the working directory PWD GetWorkingDirectory() Get the working directory SIZE GetFileSize() Get the filesize in bytes MDTM GetModifiedTime()
GetListing() with FtpListOption.Modify
GetObjectInfo() with dateModified Get the file modified date SITE CHMOD Chmod() or SetFilePermissions() Modify file permissions

File Hashing commands

Command API Description HASH GetHash() Gets the hash of a file OPTS HASH GetHashAlgorithm() / SetHashAlgorithm() Selects a hash algorithm for HASH command MD5 GetChecksum() or GetMD5() Gets the MD5 hash of a file XMD5 GetChecksum() or GetXMD5() Gets the MD5 hash of a file XSHA1 GetChecksum() or GetXSHA1() Gets the SHA-1 hash of a file XSHA256 GetChecksum() or GetXSHA256() Gets the SHA-256 hash of a file XSHA512 GetChecksum() or GetXSHA512() Gets the SHA-512 hash of a file

How do I connect with SSL/TLS? / How do I use FTPS?

Use this code:

FtpClient client = new FtpClient(hostname, username, password); // or set Host & Credentials
client.EncryptionMode = FtpEncryptionMode.Explicit;
client.SslProtocols = SslProtocols.Tls;
client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
client.Connect();

void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) {
    // add logic to test if certificate is valid here
    e.Accept = true;
}

How do I validate the server's certificate when using FTPS?

First you must discover the string of the valid certificate. Use this code to save the the valid certificate string to a file:

void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) {
    File.WriteAllText(@"C:\cert.txt", e.Certificate.GetRawCertDataString());
}

Then finally use this code to check if the recieved certificate matches the one you trust:

string ValidCert = "<insert contents of cert.txt>";
void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)  {
    if (e.PolicyErrors == SslPolicyErrors.None || e.Certificate.GetRawCertDataString() == ValidCert) {
        e.Accept = true;
    }else{
        throw new Exception("Invalid certificate : " + e.PolicyErrors);
    }
}

How do I connect with FTPS and then switch back down to plaintext FTP?

This is useful when you have a FTP firewall that requires plaintext FTP, but your server mandates FTPS connections. We use the CCC command to instruct the server to revert back to FTP.

Set this option before calling Connect() or any other method on the FtpClient class.

client.PlainTextEncryption = true;

How do I connect with SFTP?

SFTP is not supported as it is FTP over SSH, a completely different protocol. Use SSH.NET for that.

How do I login with an anonymous FTP account? / I'm getting login errors but I can login fine in Firefox/Filezilla

Do NOT set the Credentials property, so we can login anonymously. Or you can manually specify the following:

client.Credentials = new NetworkCredential("anonymous", "anonymous");

How do I login with an FTP proxy?

Create a new instance of FtpClientHttp11Proxy or FtpClientUserAtHostProxy and use FTP properties/methods like normal.

How can I upload data created on the fly?

Use Upload() for uploading a Stream or byte[].

How can I download data without saving it to disk?

Use Download() for downloading to a Stream or byte[].

How can I throttle the speed of upload/download?

Set the UploadRateLimit and DownloadRateLimit properties to control the speed of data transfer. Only honored by the high-level API, for both the synchronous and async versions, such as:

How do I verify the hash/checksum of a file and retry if the checksum mismatches?

Add the FtpVerify options to UploadFile() or DownloadFile() to enable automatic checksum verification.

// retry 3 times when uploading a file
client.RetryAttempts = 3;

// upload a file and retry 3 times before giving up
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/MyVideo.mp4", FtpExists.Overwrite, false, FtpVerify.Retry);

All the possible configurations are:

How do I upload only the missing part of a file?

Using the new UploadFile() API:

// we compare the length of the offline file vs the online file,
// and only write the missing part to the server
client.UploadFile("C:\bigfile.iso", "/htdocs/bigfile.iso", FtpExists.Append);

How do I append to a file?

Using the UploadFile() API:

// append data to an existing copy of the file
File.AppendAllText(@"C:\readme.txt", "text to be appended" + Environment.NewLine);

// only the new part of readme.txt will be written to the server
client.UploadFile("C:\readme.txt", "/htdocs/readme.txt", FtpExists.Append);

Using the stream-based OpenAppend() API:

using (FtpClient conn = new FtpClient()) {
	conn.Host = "localhost";
	conn.Credentials = new NetworkCredential("ftptest", "ftptest");
	
	using (Stream ostream = conn.OpenAppend("/full/or/relative/path/to/file")) {
		try {
			ostream.Position = ostream.Length;
			var sr = new StreamWriter(ostream);
			sr.WriteLine(...);
		}
		finally {
			ostream.Close();
			conn.GetReply(); // to read the success/failure response from the server
		}
	}
}

How does GetListing() work internally?

  1. When you call GetListing(), FluentFTP first attempts to use machine listings (MLSD command) if they are supported by the server. These are most accurate and you can expect correct file size and modification date (UTC). You may also force this mode using client.ListingParser = FtpParser.Machine, and disable it with the FtpListOption.ForceList flag. You should also include the FtpListOption.Modify flag for the most accurate modification dates (down to the second).

  2. If machine listings are not supported we fallback to the appropriate OS-specific parser (LIST command), listed below. You may force usage of a specific parser using client.ListingParser = FtpParser.*.

  3. And if none of these satisfy you, you can fallback to name listings (NLST command), which are much slower than either LIST or MLSD. This is because NLST only sends a list of filenames, without any properties. The server has to be queried for the file size, modification date, and type (file/folder) on a file-by-file basis. Name listings can be forced using the FtpListOption.ForceNameList flag.

What kind of hashing commands are supported?

We support XCRC, XMD5, and XSHA which are non-standard commands and contain no kind of formal specification. They are not guaranteed to work and you are strongly encouraged to check the FtpClient.Capabilities flags for the respective flag (XCRC, XMD5, XSHA1, XSHA256, XSHA512) before calling these methods.

Support for the MD5 command as described here has also been added. Again, check for FtpFeature.MD5 before executing the command.

Support for the HASH command has been added to FluentFTP. It supports retrieving SHA-1, SHA-256, SHA-512, and MD5 hashes from servers that support this feature. The returned object, FtpHash, has a method to check the result against a given stream or local file. You can read more about HASH in this draft.

How do I trace FTP commands for debugging?

Do this at program startup (since its static it takes effect for all FtpClient instances.)

.NET Framework version

FtpTrace.AddListener(new ConsoleTraceListener());

.NET Standard version

FtpTrace.LogToConsole = true;

How do I log all FTP commands to a file for debugging?

Do this at program startup (since its static it takes effect for all FtpClient instances.)

.NET Framework version

FtpTrace.AddListener(new TextWriterTraceListener("log_file.txt"));

.NET Standard version

FtpTrace.LogToFile = "log_file.txt";

How do I log only critical errors to a file?

This is the recommended configuration for a production server. Only supported in .NET Framework version.

Do this at program startup (since its static it takes effect for all FtpClient instances.)

FtpTrace.LogFunctions = false;
FtpTrace.AddListener(new TextWriterTraceListener("log_file.txt"){
	Filter = new EventTypeFilter(SourceLevels.Error)
});

How do I disable logging of function calls?

Do this at program startup (since its static it takes effect for all FtpClient instances.)

FtpTrace.LogFunctions = false;

How do I omit sensitive information from the logs?

Use these settings to control what data is included in the logs:

How do I use third-party logging frameworks like NLog?

FluentFTP has a built-in TraceSource named "FluentFTP" that can be used for debugging and logging purposes. This is currently available for all .NET Framework versions except for .NET Standard. Any implementation of TraceListener can be attached to the library either programmatically or via configuration in your app.config or web.config file. This will allow for direct logging or forwarding to third-party logging frameworks.

Most tracing messages are of type Verbose or Information and can typically be ignored unless debugging. Most ignored exceptions are classified as Warning, but methods that return boolean for success/failure will log the failure reasons with the Error level. If you are using .NET Standard and the DEBUG flag is set, then all logging messages will be issued via Debug.Write(message).

Attaching TraceListener in code:

TraceListener console = ConsoleTraceListener() {
	Filter = new EventTypeFilter(SourceLevels.Verbose | SourceLevels.ActivityTracking)
};

FtpTrace.AddListener(console);

Attaching via configuration file:

<system.diagnostics>
    <trace autoflush="true"></trace>
    <sources>
        <source name="FluentFTP">
	    <listeners>
	        <clear />
	        <!-- Attach a Console Listener -->
		<add name="console />
		<!-- Attach a File Trace Listener -->
		<add name="file" />
		<!-- Attach a Custom Listener -->
		<add name="myLogger" />
		<!--Attach NLog Trace Listener -->
		<add name="nlog" />	
	    </listeners>
	</source>
    </sources>
    <sharedListeners>
        <!--Define Console Listener -->
	<add name="console" type="System.Diagnostics.ConsoleTraceListener" />
	<!--Define File Listener -->
	<add name="file" type="System.Diagnostics.TextWriterTraceListener
	 initializeData="outputFile.log">
	    <!--Only write errors -->
	    <filter type="System.Diagnostics.EventTypeFilter" initializeData="Error" />
	</add>
	<!--Define Custom Listener -->
	<add name="custom" type="MyNamespace.MyCustomTraceListener />
	<!-- Define NLog Logger -->
	<add name="nlog" type="NLog.NLogTraceListener, NLog" />
    </sharedListeners>
</system.diagnostics>

What does EnableThreadSafeDataConnections do?

EnableThreadSafeDataConnections is an older feature built by the original author. If true, it opens a new FTP client instance (and reconnects to the server) every time you try to upload/download a file. It used to be the default setting, but it affects performance terribly so I disabled it and found many issues were solved as well as performance was restored. I believe if devs want multi-threaded uploading they should just start a new BackgroundWorker and create/use FtpClient within that thread. Try that if you want concurrent uploading, it should work fine.

How can I contribute some changes to FluentFTP? / How do I submit a pull request?

First you must "fork" FluentFTP, then make changes on your local version, then submit a "pull request" to request me to merge your changes. To do this:

  1. Click Fork on the top right of this page
  2. Open your version here : https://github.com/YOUR_GITHUB_USERNAME/FluentFTP
  3. Download Github Desktop and login to your account
  4. Click + (top left) then Clone and select FluentFTP and click Clone/OK
  5. Select a folder on your PC to place the files
  6. Edit the files using any editor
  7. Click FluentFTP on the list (left pane) in Github Desktop
  8. Click Changes (top)
  9. Type a Summary, and click Commit (bottom)
  10. Click Sync (top right)
  11. Open the pull requests page to create a PR
  12. Click New pull request (top right)
  13. Click compare across forks (blue link, top right)
  14. On the right "head fork" select the fork with your username
  15. Click Create pull request
  16. Summarize the changes you made in the title
  17. Type details about the changes you made in the description
  18. Click Create pull request
  19. Thank you!

How do I use client certificates to login with FTPS?

When you are using Client Certificates, be sure that:

  1. You use X509Certificate2 objects, not the incomplete X509Certificate implementation.

  2. You do not use pem certificates, use p12 instead. See this Stack Overflow thread for more information. If you get SPPI exceptions with an inner exception about an unexpected or badly formatted message, you are probably using the wrong type of certificate.

How do I bundle an X509 certificate from a file?

You need the certificate added into your local store, and then do something like this:

FluentFTP.FtpClient client = new FluentFTP.FtpClient("WWW.MYSITE.COM", "USER","PASS");

// Select certificate and add to client
X509Store store = new X509Store("MY", StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Select a certificate", "Select a certificate", X509SelectionFlag.MultiSelection); 

if (scollection.Count != 1)
{
    throw new Exception("Error: You have not chosen exactly one certificate");
 }
foreach (X509Certificate2 x509 in scollection)
{
    client.ClientCertificates.Add(x509);
}
store.Close();

//client.ReadTimeout = 10000;
client.Connect();

This is another way. And use X509Certificate2. I've been unable to get X509Certificate to work and from my reading it's because it's an incomplete implementation.

public void InitSFTP(){

    FluentFTP.FtpClient client = new FluentFTP.FtpClient("WWW.MYSITE.COM", "USER", "PASS");
    X509Certificate2 cert_grt = new X509Certificate2("C:\mycert.xyz"); 
    conn.EncryptionMode = FtpEncryptionMode.Explicit; 
    conn.DataConnectionType = FtpDataConnectionType.PASV; 
    conn.DataConnectionEncryption = true; 
    conn.ClientCertificates.Add(cert_grt); 
    conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate); 
    conn.Connect();
}       

private void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
    e.Accept = true;
}

FluentFTP fails to install in Visual Studio 2010 (VS2010) > 'System.Runtime' already has a dependency defined for 'FluentFTP'.

Your VS has an older version of nuget.exe so it cannot properly install the latest FluentFTP. You must download nuget.exe` manually and run these commands:

cd D:\Projects\MyProjectDir
C:\Nuget\nuget.exe install FluentFTP

After uploading a file with special characters like "Caffè.png" it appears as "Caff?.bmp" on the FTP server. The server supports only ASCII but "è" is ASCII. FileZilla can upload this file without problems.

Set the connection encoding manually to ensure that special characters work properly

client.Encoding = System.Text.Encoding.GetEncoding(1252); // ANSI codepage 1252

I keep getting TimeoutException's in my Azure WebApp

First try reducing the socket polling interval, which Azure needs.

client.SocketPollInterval = 1000;

If that doesn't work then try reducing the timeouts too.

client.SocketPollInterval = 1000;
client.ConnectTimeout = 2000;
client.ReadTimeout = 2000;
client.DataConnectionConnectTimeout = 2000;
client.DataConnectionReadTimeout = 2000;

If none of these work, remember that Azure has in intermittent bug wherein it changes the IP-address during a FTP request. The connection is established with IP-address A and for the data transfer Azure uses IP-address B and this isn't allowed on many firewalls. This is a known Azure bug.

Many commands don't work on Windows CE

According to this from MSDN the Windows CE implementation of FTP is the bare minimum, and open to customization via source code. Many advanced commands such as CHMOD are unsupported.

After successfully transfering a single file with OpenWrite/OpenAppend, the subsequent files fail with some random error, like "Malformed PASV response"

You need to call FtpReply status = GetReply() after you finish transfering a file to ensure no stale data is left over, which can mess up subsequent commands.

SSL Negotiation is very slow during FTPS login

FluentFTP uses SslStream under the hood which is part of the .NET framework. SslStream uses a feature of windows for updating root CA's on the fly, which can cause a long delay in the certificate authentication process. This can cause issues in FluentFTP related to the SocketPollInterval property used for checking for ungraceful disconnections between the client and server. This MSDN Blog covers the issue with SslStream and talks about how to disable the auto-updating of the root CA's.

FluentFTP logs the time it takes to authenticate. If you think you are suffering from this problem then have a look at Examples\Debug.cs for information on retrieving debug information.

Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host

This means that on the server the [FTP daemon] service isn't running (probably not the case) or the service is currently still busy performing another operation. It almost sounds like the server is returning a message indicating it is still performing the last operation.

Try reducing the polling interval to ensure that the connection does not time-out.

client.SocketPollInterval = 1000;

FluentFTP returns a Stream object for file transfers. This stream must be properly closed when you are done. Do not leave it for the GC to cleanup otherwise you can end up with uncatchable exceptions, i.e., a program crash. The stream objects are actually wrappers around NetworkStream and SslStream which perform cleanup routines on the control connection when the stream is closed. These cleanup routines can trigger exceptions so it's vital that you properly dispose the objects when you are done, no matter what. A proper implementation should go along the lines of:

try {
   using(Stream s = ftpClient.OpenRead()) {
       // perform your transfer
   }
   ftpClient.GetReply() // read success/failure messages from server
}
catch(Exception) {
   // Typical exceptions here are IOException, SocketException, or a FtpCommandException
}

The using statement above will ensure that Dispose() is called on the stream which in turn will call Close() so that the necessary cleanup routines on the control connection can be performed. If an exception is triggered you will have a chance to catch and handle it. Another valid approach might look like so:

Stream s = null;

try {
	s = ftpClient.OpenRead();
	// perform transfer
}
finally {
	if(s != null)
		s.Close()
	ftpClient.GetReply() // read success/failure messages from server
}

The finally block above ensures that Close() is always called on the stream even if a problem occurs. When Close() is called any resulting exceptions can be caught and handled accordingly.

FluentFTP includes exception handling in key places where uncatchable exceptions could occur, such as the Dispose() methods. The problem is that part of the cleanup process involves closing out the internal sockets and streams. If Dispose() was called because of an exception and triggers another exception while trying to clean-up you could end up with an un-catchable exception resulting in an application crash. To deal with this FtpClient.Dispose() and FtpSocketStream.Dispose() are setup to handle SocketException and IOException and discard them. The exceptions are written to the FtpTrace TraceListeners for debugging purposes, in an effort to not hide important errors while debugging problems with the code.

The exception that propagates back to your code should be the root of the problem and any exception caught while disposing would be a side affect however while testing your project pay close attention to what's being logged via FtpTrace. See the Debugging example for more information about using TraceListener objects with FluentFTP.

Handling Ungraceful Interruptions in the Control Connection

FluentFTP uses Socket.Poll() to test for connectivity after a user-definable period of time has passed since the last activity on the control connection. When the remote host closes the connection there is no way to know, without triggering an exception, other than using Poll() to make an educated guess. When the connectivity test fails the connection is automatically re-established. This process helps a great deal in gracefully reconnecting however it does not eliminate your responsibility for catching IOExceptions related to an ungraceful interruption in the connection. Usually, maybe always, when this occurs the InnerException will be a SocketException. How you want to handle the situation from there is up to you.

try {
    // ftpClient.SomeMethod();
}
catch(IOException e) {
    if(e.InnertException is SocketException) {
         // the control connection was interrupted
    }
}

If you just wanting to enable pipelining (in FtpClient and FtpControlConnection), set the EnablePipelining property to true. Hopefully this is all you need but it may not be. Some servers will drop the control connection if you flood it with a lot of commands. This is where the MaxPipelineExecute property comes into play. The default value here is 20, meaning that if you have 100 commands queued, 20 of the commands will be written to the underlying socket and 20 responses will be read, then the next 20 will be executed, and so forth until the command queue is empty. The value 20 is not a magic number, it's just the number that I deemed stable in most scenarios. If you increase the value, do so knowing that it could break your control connection.

Pipelining your own Commands

Pipelining your own commands is not dependent on the EnablePipelining feature. The EnablePipelining property only applies to internal pipelining performed by FtpClient and FtpControlConnection. You can use the facilities for creating pipelines at your own discretion.

If you need to cancel your pipeline in the middle of building your queue, you use the CancelPipeline() method. These methods are implemented in the FtpControlConnection class so people that are extending this class also have access to them. This feature is also used in FtpClient.GetListing() to retrieve last write times of the files in the listing when the LIST command is used.

You don't need to worry about locking the command channel (LockControlConnection() or UnlockControlConnection()) because the code that handles executing the pipeline does so for you.

Here's a quick example:

FtpClient cl = new FtpClient();

...

// initalize the pipeline
cl.BeginExecute();

// execute commands as normal
cl.Execute("foo");
cl.Execute("bar");
cl.Execute("baz");

...

// execute the queued commands
FtpCommandResult[] res = cl.EndExecute();

// check the result status of the commands
foreach(FtpCommandResult r in res) {
	if(!r.ResponseStatus) {
          // we have a failure
	}
}

When doing a large number of transfers, one needs to be aware of some inherit issues with data streams. When a socket is opened and then closed, the socket is left in a linger state for a period of time defined by the operating system. The socket cannot reliably be re-used until the operating system takes it out of the TIME WAIT state. This matters because a data stream is opened when it's needed and closed as soon as that specific task is done:

This is not a bug in FluentFTP. RFC959 says that EOF on stream mode transfers is signaled by closing the connection. On downloads and file listings, the sockets being used on the server will stay in the TIME WAIT state because the server closes the socket when it's done sending the data. On uploads, the client sockets will go into the TIME WAIT state because the client closes the connection to signal EOF to the server.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4