C# FluentFTP v46.0.2 文档一

目录

概述

基本使用方法

Connection 连接

new FtpClient()

Host

Port

Credentials

Connect()

Disconnect()

Execute()

SystemType

IsConnected

Capabilities 

HasFeature()

File Management 文件管理

GetListing()

Type

Name

FullName

Created

Modified

Size

LinkTarget

LinkObject

SpecialPermissions

Chmod

OwnerPermissions

GroupPermissions

OtherPermissions

Input

GetNameListing()

UploadFile()

DownloadFile()

UploadFiles()

DownloadFiles()

GetWorkingDirectory()

SetWorkingDirectory()

CreateDirectory()

DeleteDirectory()

DeleteFile()

Rename()

FileExists()

DirectoryExists()

GetModifiedTime()

GetFileSize()

DereferenceLink()

OpenRead()

OpenWrite()

OpenAppend()

结束


概述

FluentFTP是一个完全管理的FTP客户端,它被设计为易于使用和易于扩展。它支持文件和目录列表,上传和下载文件以及SSL/TLS连接。它可以连接到基于Unix和Windows/IIS的FTP服务器。这个项目完全是用托管的C#开发的。所有的功劳都归于J.P. Trosclair,他开发并维护这个库直到2016年。FluentFTP是在MIT许可下发布的,所以它既可以用于专有的也可以用于自由/开源的应用程序。

功能特点
• 完全支持FTP、FTPS(FTP over SSL)和带客户证书的FTPS
• 所有主要服务器类型(UNIX、IIS、DOS等)的文件和目录列表
• 轻松地从服务器上传和下载一个文件
• 使用标准流轻松地从服务器上读取和写入文件数据
• 创建、追加、读取、写入、重命名和删除文件和文件夹
• 递归地删除文件夹及其所有内容
• 获取文件/文件夹信息(存在、大小、安全标志、修改日期/时间)。
• 获取和设置文件权限(所有者、组、其他)。
• 绝对或相对路径(相对于 "工作目录")。
• 获取文件的哈希值/校验值(SHA-1、SHA-256、SHA-512和MD5)。
• 支持DrFTPD的PRET命令
• 支持FTP代理(User@Host, HTTP 1.1)。
• 支持SITE CHMOD命令(仅限Unix)。
• 解除符号链接的引用
• 被动和主动的数据连接(PASV, EPSV, PORT 和 EPRT)
• 所有操作的同步和异步方法(IAsyncResult模式)。
• 使用.NET的SSLStream为控制和数据连接支持显式和隐式SSL连接
• 通过为文件传输克隆FTP控制连接来提高线程安全(可选)。
• 实施自己的内部锁定,以努力保持事务的同步性
• 当服务器支持时,包括对非标准的散列/校验命令的支持
• 使用Execute()方法轻松地发布任何不支持的FTP命令,但需要数据连接的命令除外(文件列表和传输)。
• 轻松添加对更多代理类型的支持(只需扩展FTPClientProxy)。
• 轻松地添加不支持的目录列表解析器(见CustomParser例子)。
• 使用TraceListeners进行事务记录(自动省略密码)。
• 几乎所有方法的例子(见例子)
• 不支持SFTP,因为它是通过SSH的FTP,一个完全不同的协议(使用SSH.NET)。

这些文档是我拿翻译软件翻译的,可能有些地方翻译的不准确

基本使用方法

代码

// create an FTP client 
//创建FTP客户端
FtpClient client = new FtpClient();
client.Host = "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
//获取“/htdocs”文件夹中的文件和目录列表
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  
//上传一个文件
cl.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt");

// rename the uploaded file 
//重命名上传的文件
cl.Rename("/htdocs/big.txt", "/htdocs/big2.txt");

// download the file again 
//重新下载文件
cl.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/big2.txt");

// delete the file
//删除文件
client.DeleteFile("/htdocs/big2.txt");

// delete a folder recursively
//递归删除文件夹
client.DeleteDirectory("/htdocs/extras/", true);

// check if a file exists
//检查文件是否存在
if (client.FileExists("/htdocs/big2.txt")){ }

// check if a folder exists
//检查是否存在文件夹
if (client.DirectoryExists("/htdocs/extras/")){ }

// disconnect! good bye!
//断开!再见
client.Disconnect();

Connection 连接

new FtpClient()

Creates and returns a new FTP client instance.
创建并返回一个新的FTP客户端实例

Host

The FTP server IP or hostname. Required.
FTP服务器IP或主机名。必需的。

Port

The FTP port to connect to. Default: Auto (21 or 990 depending on FTPS config)
要连接的FTP端口。默认值:Auto(21或990,取决于FTPS配置)

Credentials

The FTP username & password to use. Must be a valid user account registered with the server. Default: anonymous/anonymous
要使用的FTP用户名和密码。必须是一个在服务器上注册的有效用户账户。默认值:anonymous/匿名

Connect()

Connects to an FTP server (uses TLS/SSL if configured).
连接FTP服务器(如果配置了TLS/SSL)。

Disconnect()

Closes the connection to the server immediately.
立即关闭与服务器的连接。

Execute()

Execute a custom or unspported command.
执行自定义或不受支持的命令。

SystemType

Gets the type of system/server that we're connected to.
获取所连接的系统/服务器的类型。

IsConnected

Checks if the connection is still alive.
检查连接是否仍然存在。

Capabilities 

Gets the server capabilties (represented by flags).
获取服务器功能(由标志表示)。

HasFeature()

Checks if a specific feature (FtpCapability) is supported by the server.
检查服务器是否支持特定的特性(FtpCapability)。

File Management 文件管理

GetListing()

Get a file listing of the given directory. Returns one FtpListItem per file or folder with all available properties set. Each item contains:
获取给定目录的文件列表。为每个文件或文件夹返回一个FtpListItem,并设置所有可用属性。每项包括:

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.
对象的完整文件路径。

Created

The created date/time of the object. Default: DateTime.MinValue if not provided by server.
对象的创建日期/时间。默认值:DateTime。如果服务器没有提供MinValue。


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.
该对象的最后修改日期/时间。如果你得到不正确的值,请尝试添加FtpListOption.Modify标志,它使用另一个MDTM命令加载修改的日期/时间。默认值: 如果服务器不提供,则为DateTime.MinValue。


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.
文件的大小,单位是字节。如果你得到不正确的值,可以尝试添加FtpListOption.Size标志,它使用另一个SIZE命令加载文件大小。默认值:如果服务器不提供,则为0。


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.
链接指向的文件/文件夹。仅填充符号链接如果FtpListOption。使用DerefLink标志。


SpecialPermissions

Gets special permissions such as Stiky, SUID and SGID. *(NIX only)
获得特殊权限,如Stiky, SUID和SGID。*(无)


Chmod

The CHMOD permissions of the object. For example 644 or 755. Default: 0 if not provided by server. *(NIX only)
对象的CHMOD权限。例如644或755。如果服务器没有提供,默认值为0。*(无)


OwnerPermissions

User rights. Any combination of 'r', 'w', 'x' (using the FtpPermission enum). Default: FtpPermission.None if not provided by server. *(NIX only)
用户的权利。'r', 'w', 'x'的任何组合(使用FtpPermission enum)。默认值:FtpPermission。如果服务器没有提供,则无。*(无)


GroupPermissions

Group rights. Any combination of 'r', 'w', 'x' (using the FtpPermission enum). Default: FtpPermission.None if not provided by server. *(NIX only)
集团的权利。'r', 'w', 'x'的任何组合(使用FtpPermission enum)。默认值:FtpPermission。如果服务器没有提供,则无。*(无)


OtherPermissions

Other rights. Any combination of 'r', 'w', 'x' (using the FtpPermission enum). Default: FtpPermission.None if not provided by server. *(NIX only)
其他权利。'r', 'w', 'x'的任何组合(使用FtpPermission enum)。默认值:FtpPermission。如果服务器没有提供,则无。*(无)

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.
一个简单的命令,使用NLST命令只返回给定目录中的文件路径列表。

UploadFile()

Uploads a file from the local file system 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 of 65KB. Remote directories are NOT created if they do not exist.
从本地文件系统上传一个文件到服务器。如果成功返回true,如果失败或文件不存在返回false。如果出现严重错误,则抛出异常。支持非常大的文件,因为它以65KB的数据块上传数据。如果远程目录不存在,则不创建这些目录。

DownloadFile()

Downloads a file from the server to the local file system. 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 of 65KB. Local directories are created if they do not exist.
从服务器下载一个文件到本地文件系统。如果成功返回true,如果失败或文件不存在返回false。如果出现严重错误,则抛出异常。支持非常大的文件,因为它以65KB为单位下载数据。如果本地目录不存在,则创建本地目录。

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. All exceptions during file upload are absorbed internally. Prefer using this method over calling UploadFile() multiple times, as this method performs a single GetListing() to check for file existance.
从本地文件系统上传多个文件到服务器上的一个文件夹。返回上传的文件数量。跳过的文件不计算在内。文件上传过程中的所有异常都在内部被吸收。与多次调用UploadFile()相比,更倾向于使用此方法,因为此方法只执行了一次GetListing()来检查文件是否存在。

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. All exceptions during file download are absorbed internally.
将多个文件从服务器下载到本地文件系统上的单个目录。返回下载的文件数。跳过的文件不计算在内。文件下载期间的所有异常都在内部吸收。

GetWorkingDirectory()

Gets the full path of the current working directory.
获取当前工作目录的完整路径。

SetWorkingDirectory()

Sets the full path of the current working directory.
设置当前工作目录的完整路径。

CreateDirectory()

Creates a directory on the server. If the parent directories do not exist they are also created.
在服务器上创建一个目录。如果父目录不存在,也会创建它们。

DeleteDirectory()

Deletes the specified directory on the server. If it is not empty then all subdirectories and files are recursively deleted.
删除服务器上的指定目录。如果不为空,则递归删除所有子目录和文件。

DeleteFile()

Deletes the specified file on the server.
删除服务器上的指定文件。

Rename()

Renames the file/directory on the server.
重命名服务器上的文件/目录。

FileExists()

Check if a file exists on the server.
检查服务器上是否存在文件。

DirectoryExists()

Check if a directory exists on the server.
检查服务器上是否存在目录。

GetModifiedTime()

Gets the last modified date/time of the file or folder.
获取文件或文件夹的最后修改日期/时间。

GetFileSize()

Gets the size of the file in bytes, or -1 if not found.
获取文件的大小(以字节为单位),如果未找到则获取-1。

DereferenceLink()

Recursively dereferences a symbolic link and returns the full path if found. The MaximumDereferenceCount property controls how deep we recurse before giving up.
递归地解引用符号链接,如果找到则返回完整路径。MaximumDereferenceCount属性控制在放弃之前递归的深度。

OpenRead()

Low level. Not recommended for general usage. Open a stream to the specified file for reading. Returns a standard Stream.
低的水平。不建议一般使用。打开指定文件的流进行读取。返回一个标准的流。

OpenWrite()

Low level. Not recommended for general usage. Opens a stream to the specified file for writing. Returns a standard Stream, any data written will overwrite the file, or create the file if it does not exist.
低的水平。不建议一般使用。打开指定文件的流以进行写入。返回一个标准流,任何写入的数据都将覆盖文件,如果文件不存在,则创建该文件。

OpenAppend()

Low level. Not recommended for general usage. Opens a stream to the specified file for appending. Returns a standard Stream, any data written wil be appended to the end of the file.
低的水平。不建议一般使用。打开要追加的指定文件的流。返回一个标准的流,任何写入的数据将被追加到文件的末尾。
 

结束

如果这个帖子对你有所帮助,欢迎 关注 + 点赞 + 留言

end

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

熊思宇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值