如何在C#中发送任意的FTP命令 [英] How to send arbitrary FTP commands in C#

查看:587
本文介绍了如何在C#中发送任意的FTP命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现上传,下载,删除等使用的FtpWebRequest 类在C#中的能力。这是相当简单的。

I have implemented the ability to upload, download, delete, etc. using the FtpWebRequest class in C#. That is fairly straight forward.

我现在需要做的就是支持发送任意的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 。我可能会尝试下 Web客户端类。任何人都可以点我在正确的方向更快?谢谢!

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!

更新:
我来了同样的结论,因为.NET框架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命令是通过方法属性和文档指出:

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 类中定义的字符串是的方法属性,唯一支持的选项。在方法属性设置为任何其他值将导致的ArgumentException 例外。

Note that the strings defined in the WebRequestMethods.Ftp class are the only supported options for the Method property. Setting the Method property to any other value will result in an ArgumentException exception.

网站和SYST不pdefined选项$ P $之间,所以我想你就完蛋了...

SITE and SYST are not among the predefined options, so I guess you're stuck...

不要浪费时间去尝试的 Web客户端类,它会给你比的FtpWebRequest 甚至更少的灵活性。

Don't waste time to try the WebClient class, it will give you even less flexibility than FtpWebRequest.

不过,也有大量的第三方FTP实现,开源或商业,我pretty肯定他们中的一些可以处理自定义命令...

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...

这篇关于如何在C#中发送任意的FTP命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆