如何在 C# 中发送任意 FTP 命令

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

问题描述

我已经使用 C# 中的 FtpWebRequest 类实现了上传、下载、删除等功能.这是相当直接的.

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 来做到这一点.接下来我可能会尝试 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!

更新:我得出了同样的结论,从 .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 属性设置为任何其他值将导致 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.

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 实现,开源的或商业的,我很确定其中一些可以处理自定义命令...

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 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)