FTPS(基于SSL的FTP)在C# [英] FTPS (FTP over SSL) in C#
问题描述
我需要一些指导。我需要开发在C#中的自定义FTP,应该使用app.config文件进行配置。另外,在FTP应的数据推到任何服务器从任何客户端再次取决于配置文件。 我将AP preciate如果有人能指导,如果有任何API或任何其他有用的建议,或移动我在正确的方向。
I need some guidance. I need to develop a customizable FTP in C# that should be configured using App.Config file. Also, the FTP should push the data to any server from any client again depends on config file. I will appreciate if someone can guide, if there is any API or any other useful suggestion, or move me in the right direction.
感谢
推荐答案
您可以使用的FtpWebRequest ;但是,这是相当低的水平。有一个较高级别的类 Web客户端,该需要少得多的$ C $下很多场景;但是,默认情况下不支持FTP / SSL。幸运的是,你可以通过注册自己的preFIX使用FTP / SSL的Web客户端的工作:
You can use FtpWebRequest; however, this is fairly low level. There is a higher-level class WebClient, which requires much less code for many scenarios; however, it doesn't support FTP/SSL by default. Fortunately, you can make WebClient work with FTP/SSL by registering your own prefix:
private void RegisterFtps()
{
WebRequest.RegisterPrefix("ftps", new FtpsWebRequestCreator());
}
private sealed class FtpsWebRequestCreator : IWebRequestCreate
{
public WebRequest Create(Uri uri)
{
FtpWebRequest webRequest = (FtpWebRequest)WebRequest.Create(uri.AbsoluteUri.Remove(3, 1)); // Removes the "s" in "ftps://".
webRequest.EnableSsl = true;
return webRequest;
}
}
一旦你这样做,你可以使用的WebRequest几乎就像正常的,只是你的URI以FTPS://,而不是FTP://。一个需要注意的是,你必须指定方法,因为不会有一个默认的。例如,
Once you do this, you can use WebRequest almost like normal, except that your URIs start with "ftps://" instead of "ftp://". The one caveat is that you have to specify the method, since there won't be a default one. E.g.
// Note here that the second parameter can't be null.
webClient.UploadFileAsync(uploadUri, WebRequestMethods.Ftp.UploadFile, fileName, state);
这篇关于FTPS(基于SSL的FTP)在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!