gpt4 book ai didi

c# - 关于 .Net ftp 类和被动模式 c# 的使用

转载 作者:太空宇宙 更新时间:2023-11-03 13:45:11 28 4
gpt4 key购买 nike

我们都知道 .Net 有 ftp 相关的类,我经常看到人们总是使用 ftp 的几个属性:

wrq.KeepAlive = false;
wrq.UseBinary = false;
wrq.UsePassive = true;

谁能告诉我KeepAliveUseBinaryUsePassive 是什么意思?

当我们为上面的属性设置true或false时会发生什么,具体告诉我UsePassive属性的用法或意义是什么。

一个人简单解释一下被动模式:-

使用被动:
如果客户端应用程序的数据传输进程监听数据端口上的连接,则为 false;否则,如果客户端应在数据端口上启动连接,则为 true。默认值为真

上面的回答我不是很清楚。所以任何人都可以更详细地解释被动模式....谢谢

最佳答案

也许这些 MSDN 文章可以帮助您?

KeepAlive

Gets or sets a Boolean value that specifies whether the control connection to the FTP server is closed after the request completes.

When the KeepAlive property is set to false, the control connection is closed when you call the Close method.

Changing KeepAlive after calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method causes an InvalidOperationException exception.

http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.keepalive.aspx


UseBinary

Gets or sets a Boolean value that specifies the data type for file transfers.

If you are sending binary data, such as an image, set this property to true. If you are sending text, set the property to false. Specifying true causes the FtpWebRequest to send a "TYPE I" command to the server. Specifying false causes the FtpWebRequest to send a "Type A" command to the server. FTP servers can ignore these commands.

Changing UseBinary after calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method causes an InvalidOperationException exception.

http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.usebinary.aspx


UsePassive

Gets or sets the behavior of a client application's data transfer process.

Setting the UsePassive property to true sends the "PASV" command to the server. This command requests the server to listen on a data port and to wait for a connection rather than initiate one upon receipt of a transfer command.

For a description of the behaviors that are specified using UsePassive, see RFC 959, "File Transfer Protocol," Section 3.2, "Establishing Data Connections" and Section 4.1.2, "Transfer Parameter Commands," available at http://www.rfc-editor.org/.

Changing UsePassive after calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method causes an InvalidOperationException exception.

If UsePassive is set to true, the FTP server may not send the size of the file, and download progress can always be zero. If UsePassive is set to false, a firewall can raise an alert and block the file download.

http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.usepassive.aspx

关于c# - 关于 .Net ftp 类和被动模式 c# 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15602953/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com