問題描述
我已經(jīng)使用 C# 中的 FtpWebRequest
類實現(xiàn)了上傳、下載、刪除等功能.這是相當直接的.
I have implemented the ability to upload, download, delete, etc. using the FtpWebRequest
class in C#. That is fairly straight forward.
我現(xiàn)在需要做的是支持發(fā)送任意FTP命令如
What I need to do now is support sending arbitrary FTP commands such as
quote SITE LRECL=132 RECFM=FB
or
quote SYST
這是直接來自我們的 app.config
的示例配置:
Here's an example configuration straight from our app.config
:
<!-- The following commands will be executed before any uploads occur -->
<extraCommands>
<command>quote SITE LRECL=132 RECFM=FB</command>
</extraCommands>
我仍在研究如何使用 FtpWebRequest
來做到這一點.接下來我可能會嘗試 WebClient
類.任何人都可以更快地指出我正確的方向嗎?謝謝!
I'm still researching how to do this using FtpWebRequest
. I'll probably try WebClient
class next. Anyone can point me in the right direction quicker? Thanks!
更新:我得出了同樣的結(jié)論,從 .NET Framework 3.5 FtpWebRequest
開始,除了 WebRequestMethods.Ftp.*
.我將嘗試其他一些帖子推薦的第三方應用程序.謝謝您的幫助!
UPDATE:
I've come to that same conclusion, as of .NET Framework 3.5 FtpWebRequest
doesn't support anything except what's in WebRequestMethods.Ftp.*
. I'll try a third party app recommended by some of the other posts. Thanks for the help!
推薦答案
我不認為用 FtpWebRequest
... 指定 FTP 命令的唯一方法是通過 Method
屬性,文檔說明:
I don't think it can be done with FtpWebRequest
... The only way to specify a FTP command is through the Method
property, and the documentation states :
請注意,WebRequestMethods.Ftp
類中定義的字符串是 Method
屬性唯一受支持的選項.將 Method
屬性設(shè)置為任何其他值將導致 ArgumentException
異常.
Note that the strings defined in the
WebRequestMethods.Ftp
class are the only supported options for theMethod
property. Setting theMethod
property to any other value will result in anArgumentException
exception.
SITE 和 SYST 不在預定義選項中,所以我猜你被卡住了...
SITE and SYST are not among the predefined options, so I guess you're stuck...
不要浪費時間嘗試 WebClient
類,它給你的靈活性比 FtpWebRequest
還要低.
Don't waste time to try the WebClient
class, it will give you even less flexibility than FtpWebRequest
.
但是,有很多第三方 FTP 實現(xiàn),開源的或商業(yè)的,我很確定其中一些可以處理自定義命令...
However, there are plenty of third-party FTP implementation, open source or commercial, and I'm pretty sure some of them can handle custom commands...
這篇關(guān)于如何在 C# 中發(fā)送任意 FTP 命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!