A RetroSearch Logo

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

Search Query:

Showing content from https://github.com/robinrodricks/FluentFTP/wiki/File-Transfer below:

File Transfer · robinrodricks/FluentFTP Wiki · GitHub

Tip: For detailed documentation refer to the IntelliSense tips that appear when you call a given API method.

To increase file transfer speed To limit file transfer speed To configure transfer methods How can I track the progress of file transfers?

All of the high-level methods provide a progress argument that can be used to track upload/download progress.

To use this, first create a callback method to provide to the Upload/Download method. This will be called with an FtpProgress object, containing the percentage transferred as well as various statistics.

If you are creating your UI in WinForms, create a ProgressBar with the Minimum = 0 and Maximum = 100.

Using the asynchronous API:

// Callback method that accepts a FtpProgress object
Progress<FtpProgress> progress = new Progress<FtpProgress>(x => {

	// When progress in unknown, -1 will be sent
	if (x.Progress < 0){
		progressBar.IsIndeterminate = true;
	}else{
		progressBar.IsIndeterminate = false;
		progressBar.Value = x;
	}
});

Using the synchronous API:

// Callback method that accepts a FtpProgress object
Action<FtpProgress> progress = new Action<FtpProgress>(x => {

	// When progress in unknown, -1 will be sent
	if (x.Progress < 0){
		progressBar.IsIndeterminate = true;
	}else{
		progressBar.IsIndeterminate = false;
		progressBar.Value = x;
	}
});

Now call the Upload/Download method providing the new progress object that you just created.

Using the asynchronous API:

await client.DownloadFileAsync(localPath, remotePath, FtpLocalExists.Overwrite, FluentFTP.FtpVerify.Retry, progress);

Using the synchronous API:

client.DownloadFile(localPath, remotePath, FtpLocalExists.Overwrite, FluentFTP.FtpVerify.Retry, progress);

For .NET 2.0 users, pass an implementation of the IProgress class. The Report() method of the object you pass will be called with the progress value.

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 resume downloading a file?

Use DownloadFile() or DownloadFiles() with the existsMode set to FtpLocalExists.Append.

// download only the missing part of the file
// by comparing its file size to the size of the local file
client.DownloadFile(@"C:\MyVideo.mp4", "/htdocs/MyVideo.mp4", FtpLocalExists.Append);

Other options are:

How can I resume uploading 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", FtpRemoteExists.Resume);
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:

See this post for more information on the recent improvements to throttling.

How do I append to a file?

Using the UploadFile() API to upload only the newly added part of the file (eg. for log files):

// 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", FtpRemoteExists.Resume);

Using the UploadFile() API to upload the given file to the end of the remote file:

// the entire readme.txt will be written to the end of the file on the serer
client.UploadFile("C:\readme.txt", "/htdocs/readme.txt", FtpRemoteExists.AddToEnd);

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 can I upload/download files with Unicode filenames when my server does not support UTF8?

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

The default codepage that you should use is 1252 Windows Western. It has support for English + European characters (accented chars).

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

Here is the full list of codepages based on the charset you need:

Why do DownloadFile and DownloadFiles return different data types?

The return type between these 2 functions are fundamentally different for a very simple reason. They both behave differently.

Same reasoning applies to UploadFile and UploadFiles.

We like minimizing complexity, therefore using a simpler return type FtpStatus is better in this case because the more complex FtpResult is not required.

You can use the FtpResult.ToStatus() API to obtain a FtpStatus enum value and easily compare it against another enum value.


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