C#中的FTPS(FTP over SSL)

我需要一些指导。 我需要在C#中开发一个可自定义的FTP,它应该使用App.Config文件进行配置。 此外,FTP应该再次从任何客户端将数据推送到任何服务器依赖于配置文件。

如果有人可以指导,如果有任何API或任何其他有用的建议,或者让我朝着正确的方向前进,我将不胜感激。

你可以使用FtpWebRequest ; 然而,这是相当低的水平。 有一个更高级别的WebClient类,它在许多场景中需要的代码要少得多; 但是,默认情况下它不支持FTP / SSL。 幸运的是,您可以通过注册自己的前缀使WebClient与FTP / SSL一起使用:

 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; } } 

一旦你这样做,你几乎可以WebClient使用WebClient ,除了你的URI以“ftps://”而不是“ftp://”开头。 需要注意的是,您必须指定method参数,因为不会有默认参数。 例如

 using (var webClient = new WebClient()) { // Note here that the second parameter can't be null. webClient.UploadFileAsync(uploadUri, WebRequestMethods.Ftp.UploadFile, fileName, state); } 

我们使用edtFTPnet并取得了良好的效果。