就像标题说的那样,我想知道使用 WebClient 是否是每天将文件传输到 ftp 的合适工具?经过一番阅读,在我看来,它没有返回 ftps 响应代码。
谁能推荐这方面的良好做法,或者推荐使用框架的哪一部分?
我想第三种选择是重写现有的 Ftp 功能。
今天存在以下内容,并且是从另一个类中调用的:
using System.Net;
public class WebClientAdapter : IWebClientAdapter
{
private WebClient _webClient = new WebClient();
public ICredentials Credentials
{
get { return _webClient.Credentials; }
set { _webClient.Credentials = value; }
}
public byte[] UploadFile(string address, string fileName)
{
return _webClient.UploadFile(address, fileName);
}
using System.Net;
public class FtpHandler
{
public string Path { get; private set; }
private const string Uri = "PathToFtp";
private const string FileName = "SomeFile";
private IWebClientAdapter _webClientAdapter;
public IWebClientAdapter WebClientAdapter
{
get
{
if (_webClientAdapter == null)
_webClientAdapter = new WebClientAdapter();
return _webClientAdapter;
}
set { _webClientAdapter = value; }
}
public FtpHandler()
{
Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), FileName);
}
public void Upload()
{
WebClientAdapter.Credentials = new NetworkCredential("user", "pass");
WebClientAdapter.UploadFile(Uri, Path);
}
}
由于公司政策,我删除了一些命名空间、凭据和名称。