FluentFTP-master

所属分类:网络编程
开发工具:C#
文件大小:223KB
下载次数:3
上传日期:2019-11-06 10:39:09
上 传 者Dk02ssq
说明:  ftp客户端操作,基于微软vs自带ftp升级的ftp客户端。
(FTP client operation, based on Microsoft vs own FTP upgrade FTP client.)

文件列表:
.editorconfig (26, 2019-09-30)
FluentFTP.Examples (0, 2019-09-30)
FluentFTP.Examples\AsyncConnect.cs (685, 2019-09-30)
FluentFTP.Examples\BeginConnect.cs (1195, 2019-09-30)
FluentFTP.Examples\BeginCreateDirectory.cs (1343, 2019-09-30)
FluentFTP.Examples\BeginDeleteDirectory.cs (1295, 2019-09-30)
FluentFTP.Examples\BeginDeleteFile.cs (1230, 2019-09-30)
FluentFTP.Examples\BeginDereferenceLink.cs (1904, 2019-09-30)
FluentFTP.Examples\BeginDirectoryExists.cs (1306, 2019-09-30)
FluentFTP.Examples\BeginDisconnect.cs (1220, 2019-09-30)
FluentFTP.Examples\BeginExecute.cs (1374, 2019-09-30)
FluentFTP.Examples\BeginFileExists.cs (1290, 2019-09-30)
FluentFTP.Examples\BeginGetFileSize.cs (1294, 2019-09-30)
FluentFTP.Examples\BeginGetListing.cs (1397, 2019-09-30)
FluentFTP.Examples\BeginGetModifiedTime.cs (1333, 2019-09-30)
FluentFTP.Examples\BeginGetNameListing.cs (1483, 2019-09-30)
FluentFTP.Examples\BeginGetWorkingDirectory.cs (1340, 2019-09-30)
FluentFTP.Examples\BeginOpenAppend.cs (1649, 2019-09-30)
FluentFTP.Examples\BeginOpenRead.cs (1879, 2019-09-30)
FluentFTP.Examples\BeginOpenWrite.cs (1643, 2019-09-30)
FluentFTP.Examples\BeginRename.cs (1244, 2019-09-30)
FluentFTP.Examples\BeginSetWorkingDirectory.cs (1282, 2019-09-30)
FluentFTP.Examples\Connect.cs (317, 2019-09-30)
FluentFTP.Examples\CreateDirectory.cs (399, 2019-09-30)
FluentFTP.Examples\CustomParser.cs (4862, 2019-09-30)
FluentFTP.Examples\Debug.cs (2793, 2019-09-30)
FluentFTP.Examples\DeleteDirectory.cs (418, 2019-09-30)
FluentFTP.Examples\DeleteFile.cs (358, 2019-09-30)
FluentFTP.Examples\DereferenceLink.cs (3137, 2019-09-30)
FluentFTP.Examples\DirectoryExists.cs (399, 2019-09-30)
FluentFTP.Examples\Examples.csproj (300, 2019-09-30)
FluentFTP.Examples\Execute.cs (437, 2019-09-30)
FluentFTP.Examples\Extensions.cs (550, 2019-09-30)
FluentFTP.Examples\FileExists.cs (507, 2019-09-30)
FluentFTP.Examples\GetChecksum.cs (1026, 2019-09-30)
FluentFTP.Examples\GetFileSize.cs (425, 2019-09-30)
FluentFTP.Examples\GetHash.cs (1585, 2019-09-30)
FluentFTP.Examples\GetHashAlgorithm.cs (468, 2019-09-30)
... ...

# FluentFTP [![Version](https://img.shields.io/nuget/vpre/FluentFTP.svg)](https://www.nuget.org/packages/FluentFTP) [![Downloads](https://img.shields.io/nuget/dt/FluentFTP.svg)](https://www.nuget.org/packages/FluentFTP) [![GitHub contributors](https://img.shields.io/github/contributors/robinrodricks/FluentFTP.svg)](https://github.com/robinrodricks/FluentFTP/graphs/contributors) [![Codacy grade](https://img.shields.io/codacy/grade/2d6bb3604aae4c1e892a8386363a5bfc.svg)](https://app.codacy.com/project/robinrodricks/FluentFTP/dashboard) [![License](https://img.shields.io/github/license/robinrodricks/FluentFTP.svg)](https://github.com/robinrodricks/FluentFTP/blob/master/LICENSE.TXT) 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. ## Features - Full support for [FTP](#ftp-support), [FTPS](#faq_ftps) (FTP over SSL), [FTPS with client certificates](#faq_certs) and [FTPS with CCC](#faq_ccc) (for FTP firewalls) - **File management:** - File and directory listing for [all major server types](#faq_listings) (Unix, Windows/IIS, Azure, Pure-FTPd, ProFTPD, Vax, VMS, OpenVMS, Tandem, HP NonStop Guardian, IBM OS/400, AS400, Windows CE, Serv-U, etc) - Fully recursive directory listing and directory deletion (manual recursion and server-side recursion) - Easily upload and download a file from the server with [progress tracking](#faq_progress) - Automatically [verify the hash](#faq_verifyhash) of a file & retry transfer if hash mismatches - Configurable error handling (ignore/abort/throw) for multi-file transfers - Easily read and write file data from the server using standard streams - Create, append, read, write, rename, move and delete files and folders - Recursively deletes folders and all its contents - Get file/folder info (exists, size, security flags, modified date/time) - Get and set [file permissions](#file-permissions) (owner, group, other) - Absolute or relative paths (relative to the ["working directory"](#file-management)) - Get the [hash/checksum](#file-hashing) of a file (SHA-1, SHA-256, SHA-512, and MD5) - Dereference of symbolic links to calculate the linked file/folder - [Throttling](#faq_throttle) of uploads and downloads with configurable speed limit - **FTP protocol:** - Automatic detection of [working connection settings](#faq_autodetect) and automatic [connection negotiation](#faq_autoconnect) - Automatic detection of the [FTP server software](#faq_servertype) and its [capabilities](#faq_recursivelist) - Extensive support for [FTP commands](#ftp-support), including some server-specific commands - Easily send [server-specific](https://github.com/robinrodricks/FluentFTP/issues/88) FTP commands using the `Execute()` method - Explicit and Implicit [SSL connections](#faq_ftps) are supported for the control and data connections using .NET's `SslStream` - Passive and active data connections (PASV, EPSV, PORT and EPRT) - Supports Unix CHMOD, PRET, ProFTPD's SITE MKDIR and RMDIR commands, Serv-U's RMDA command - Supports [FTP Proxies](#faq_loginproxy) (User@Host, HTTP 1.1, BlueCoat) - [FTP command logging](#faq_log) using `TraceListeners` (passwords omitted) to [trace](#faq_trace) or [log output](#faq_logfile) to a file - SFTP is not supported as it is FTP over SSH, a completely different protocol (use [SSH.NET](https://github.com/sshnet/SSH.NET) for that) - **Asynchronous support:** - Synchronous and asynchronous methods using `async`/`await` for all operations - Asynchronous methods for .NET 4.0 and below using `IAsyncResult` pattern (Begin*/End*) - All asynchronous methods can be cancelled midway by passing a `CancellationToken` - All asynchronous methods honor the `ReadTimeout` and automatically cancel themselves if timed out - Improves thread safety by cloning the FTP control connection for file transfers (optional) - Implements its own internal locking in an effort to keep transactions synchronized - **Extensible:** - Easily add support for more proxy types (simply extend [`FTPClientProxy`](https://github.com/robinrodricks/FluentFTP/blob/master/FluentFTP/Proxy/FtpClientProxy.cs)) - Easily add unsupported directory listing parsers (see the [`CustomParser`](https://github.com/robinrodricks/FluentFTP/blob/f48af030b565237ddd5d7c8937378884d20e1627/FluentFTP.Examples/CustomParser.cs) example) - Easily add custom logging/tracing functionality using [`FtpTrace.AddListener`](#faq_log) ## Releases 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](#example-usage) section and the [Documentation](#documentation) section below. - [Nuget](https://www.nuget.org/packages/FluentFTP) (latest) - [Release Notes](https://github.com/robinrodricks/FluentFTP/blob/master/RELEASES.md) (features and fixes per release) FluentFTP works on .NET and .NET Standard/.NET Core. | Platform | Binaries Folder | |--------------- |----------- | | **.NET 2.0** | net20 | | **.NET 3.5** | net35 | | **.NET 4.0** | net40 | | **.NET 4.5** | net45 | | **.NET Standard 1.4** | netstandard1.4 | | **.NET Standard 1.6** | netstandard1.6 | FluentFTP is also supported on these platforms: (via .NET Standard) - **Mono** 4.6 - **Xamarin.iOS** 10.0 - **Xamarin.Android** 10.0 - **Universal Windows Platform** 10.0 Binaries for all platforms are built from a single VS 2017 Project. You will need [VS 2017](https://visualstudio.microsoft.com/downloads/) to build or contribute to FluentFTP. ## Example Usage ```csharp // 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/MyVideo.mp4"); // rename the uploaded file client.Rename("/htdocs/MyVideo.mp4", "/htdocs/MyVideo_2.mp4"); // download the file again client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/MyVideo_2.mp4"); // delete the file client.DeleteFile("/htdocs/MyVideo_2.mp4"); // 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(); ``` ## Documentation - [API Documentation](#api) - [Connection](#connection) - [Directory Listing](#directory-listing) - [File Transfer](#file-transfer) - [File Management](#file-management) - [File Permissions](#file-permissions) - [File Hashing](#file-hashing) - [FTPS](#ftps) - [Settings](#advanced-settings) - [Utilities](#utilities) - [Logging](#logging) - [FTP Support Table](#ftp-support) - [Examples](https://github.com/robinrodricks/FluentFTP/tree/master/FluentFTP.Examples) - [Release Notes](https://github.com/robinrodricks/FluentFTP/blob/master/RELEASES.md) - [Notes](https://github.com/robinrodricks/FluentFTP/blob/master/NOTES.md) ## FAQs **Note:** Check these [FAQs and commonly asked questions](https://github.com/robinrodricks/FluentFTP/issues?q=label%3Afaq+is%3Aclosed) that have already been solved. **Logging FAQs** - [How do I trace FTP commands for debugging?](#faq_trace) - [How do I log all FTP commands to a file for debugging?](#faq_logfile) - [How do I log only critical errors to a file?](#faq_logfile2) - [How do I disable logging of function calls?](#faq_logfunc) - [How do I omit sensitive information from the logs?](#faq_hidelog) - [How do I use third-party logging frameworks like NLog?](#faq_log) **Connection FAQs** - [How do I auto-detect the correct connection settings?](#faq_autodetect) - [How do I auto-connect to an FTP or FTPS server?](#faq_autoconnect) - [How do I connect with SSL/TLS? / How do I use FTPS?](#faq_ftps) - [How do I validate the server's certificate when using FTPS?](#faq_ftps) - [How do I connect with FTPS and then switch back down to plaintext FTP?](#faq_ccc) - [How do I connect with SFTP?](#faq_sftp) - [How do I login with an anonymous FTP account?](#faq_loginanon) - [How do I login with an FTP proxy?](#faq_loginproxy) - [How do I detect the type of server I'm connecting to?](#faq_servertype) - [How do I use client certificates to login with FTPS?](#faq_certs) - [How do I bundle an X509 certificate from a file?](#faq_x509) **File Transfer FAQs** - [How can I track the progress of file transfers?](#faq_progress) - [How can I upload data created on the fly?](#faq_uploadbytes) - [How can I download data without saving it to disk?](#faq_downloadbytes) - [How can I resume downloading a file?](#faq_resumedownload) - [How can I resume uploading a file?](#faq_uploadmissing) - [How can I throttle the speed of upload/download?](#faq_throttle) - [How do I verify the hash/checksum of a file and retry if the checksum mismatches?](#faq_verifyhash) - [How do I append to a file?](#faq_append) - [How do I download files using the low-level API?](#faq_downloadlow) - [How can I upload/download files with Unicode filenames when my server does not support UTF8?](#faq_utf) **File Management FAQs** - [How does GetListing() work internally?](#faq_listings) - [How does GetListing() return a recursive file listing?](#faq_recursivelist) - [What kind of hashing commands are supported?](#faq_hashing) **Misc FAQs** - [What does `EnableThreadSafeDataConnections` do?](#faq_etsdc) - [How can I contribute some changes to FluentFTP?](#faq_fork) - [How do I submit a pull request?](#faq_fork) **Very Common Issues** - [Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host](https://github.com/robinrodricks/FluentFTP/issues/104) - [Timed out trying to read data from the socket stream!](https://github.com/robinrodricks/FluentFTP/issues/122) - [FTPS not working on Linux since SSL session resumption is not supported](https://github.com/robinrodricks/FluentFTP/issues/347) **Common Issues** - [I'm getting login errors but I can login fine in Firefox/Filezilla](#faq_loginanon) - [FluentFTP fails to install in Visual Studio 2010 : 'System.Runtime' already has a dependency defined for 'FluentFTP'.](#trouble_install) - [After uploading a file with special characters like "Caffe.png" it appears as "Caff?.bmp" on the FTP server. The server supports only ASCII but "e" is ASCII. FileZilla can upload this file without problems.](#trouble_specialchars) - [I cannot delete a file if the filename contains Russian letters. FileZilla can delete this file without problems.](#trouble_specialchars2) - [I keep getting TimeoutException's in my Azure WebApp](#trouble_azure) - [Many commands don't work on Windows CE](#trouble_windowsce) - [After successfully transfering a single file with OpenWrite/OpenAppend, the subsequent files fail with some random error, like "Malformed PASV response"](#trouble_getreply) - [SSL Negotiation is very slow during FTPS login](#trouble_ssl) ## API 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. ### Connection - **new FtpClient**() - Creates and returns a new FTP client instance. - **Host** - The FTP server IP or hostname. Required. - **Port** - The FTP port to connect to. **Default:** Auto (21 or 990 depending on FTPS config) - **Credentials** - The FTP username & password to use. Must be a valid user account registered with the server. **Default:** `anonymous/anonymous` - **Connect**() - Connects to an FTP server (uses TLS/SSL if configured). - **Disconnect**() - Closes the connection to the server immediately. - **AutoDetect**() - Automatically discover working FTP connection settings and return those connection profiles. - **AutoConnect**() - Automatically discover working FTP connection settings and use those to connect to the server. - **Execute**() - Execute a custom or unspported command. - **SystemType** - Gets the type of system/server that we're connected to. - **ServerType** - Gets the type of the FTP server software that we're connected to, using the `FtpServer` enum. See the list of [supported FTP servers](#faq_servertype). **Default:** `FtpServer.Unknown` - **ServerOS** - Gets the operating system of the FTP server software that we're connected to, using the `FtpOS` enum. See the list of [supported operating systems](#faq_servertype). **Default:** `FtpOS.Unknown` - **IsConnected** - Checks if the connection is still alive. - **Capabilities** - Gets the server capabilities (represented by flags). - **HasFeature**() - Checks if a specific feature (`FtpCapability`) is supported by the server. - **LastReply** - Returns the last `FtpReply` recieved from the server. ### Directory Listing - **GetListing**() - Get a [file listing](#faq_listings) of the given directory. Add `FtpListOption.Recursive` to [recursively list](#faq_recursivelist) all the sub-directories as well. Returns one `FtpListItem` per file or folder with all available properties set. Each item contains: - `Type` : The type of the object. (File, Directory or Link) - `Name` : The name of the object. (minus the path) - `FullName` : The full file path of the object. If filenames look wrong, select the [correct encoding](#faq_utf). - `Created` : The created date/time of the object. **Default:** `DateTime.MinValue` if not provided by server. - `Modified` : The last modified date/time of the object. If you get incorrect values, try adding the `FtpListOption.Modify` flag which loads the modified date/time using another `MDTM` command. **Default:** `DateTime.MinValue` if not provided by server. - `Size` : The size of the file in bytes. If you get incorrect values, try adding the `FtpListOption.Size` flag which loads the file size using another `SIZE` command. **Default:** `0` if not provided by server. - `LinkTarget` : The full file path the link points to. Only filled for symbolic links. - `LinkObject` : The file/folder the link points to. Only filled for symbolic links if `FtpListOption.DerefLink` flag is used. - `SpecialPermissions` : Gets special permissions such as Stiky, SUID and SGID. - `Chmod` : The CHMOD permissions of the object. For example ***4 or 755. **Default:** `0` if not provided by server. - `OwnerPermissions` : User rights. Any combination of 'r', 'w', 'x' (using the `FtpPermission` enum). **Default:** `FtpPermission.None` if not provided by server. - `GroupPermissions` : Group rights. Any combination of 'r', 'w', 'x' (using the `FtpPermission` enum). **Default:** `FtpPermission.None` if not provided by server. - `OtherPermissions` : Other rights. Any combination of 'r', 'w', 'x' (using the `FtpPermission` enum). **Default:** `FtpPermission.None` if not provided by server. - `RawPermissions` : The raw permissions string received for this object. Use this if other permission properties are blank or invalid. - `Input` : The raw string that the server returned for this object. Helps debug if the above properties have been correctly parsed. - **GetNameListing**() - A simple command that only returns the list of file paths in the given directory, using the NLST command. - **GetObjectInfo()** - Get information for a single file or directory as an `FtpListItem`. It includes the type, date created, date modified, file size, permissions/chmod and link target (if any). ### File Transfer *High-level API:* - **Upload**() - Uploads a Stream or byte[] to the server. Returns true if succeeded, false if failed or file does not exist. Exceptions are thrown for critical errors. Supports very large files since it uploads data in chunks. - **Download**() - Downloads a file from the server to a Stream or byte[]. Returns true if succeeded, false if failed or file does not exist. Exceptions are thrown for critical errors. Supports very large files since it downloads data in chunks. - **UploadFile**() - Uploads a file from the local file system to the server. Use `FtpExists.Append` to resume a partial upload. Returns true if succeeded, false if failed or file does not exist. Exceptions are thrown for critical errors. Supports very large files since it uploads data in chunks. Optionally [verifies the hash](#faq_verifyhash) of a file & retries transfer if hash mismatches. - **DownloadFile**() - Downloads a file from the server to the local file system. Use `FtpLocalExists.Append` to resume a partial download. Returns true if succeeded, false if failed or file does not exist. Exceptions are thrown for critical errors. Supports very large files since it downloads data in chunks. Local directories are created if they do not exist. Optionally [verifies the hash](#faq_verifyhash) of a file & retries transfer if hash mismatches. - **UploadFiles**() - Uploads multiple files from the local file system to a single folder on the server. Returns the number of files uploaded. Skipped files are not counted. User-defined error handling for exceptions during file upload (ignore/abort/throw). Optionally [verifies the hash](#faq_verifyhash) of a file & retries transfer if hash mismatches. Faster than calling `UploadFile()` multiple times. - **DownloadFiles**() - Downloads multiple files from server to a single directory on the local file system. Returns the number of files downloaded. Skipped files are not counted. User-defined error handling for exceptions during file download (ignore/abort/throw). Optionally [verifies the hash](#faq_verifyhash) of a file & retries transfer if hash mismatches. *Low-level API:* - **OpenRead**() - *(Prefer using `Download()` for downloading to a `Stream` or `byte[]`)* Open a stream to the specified file for reading. Returns a [standard `Stream`](#stream-handling). Please call `GetReply()` after you have successfully transfered the file to read the "OK" command sent by the server and prevent stale ... ...

近期下载者

相关文件


收藏者