0

タイトルが示すように、WebClient の使用は、日常的にファイルを ftp に転送するために使用する適切なツールであるかどうか疑問に思っています。少し読んだ後、ftps 応答コードが返されないように思えます。

誰かがこれに関する良い実践を推奨できますか? あるいは、フレームワークのどの部分を使用するかを推奨できますか?

3 番目の選択肢は、既存の 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);
        }
    }

会社のポリシーにより、一部の名前空間、資格情報、および名前を削除しました。

4

1 に答える 1

2

FtpWebRequest-Classの使用を検討する必要があります。これには必要なものがすべて含まれています。

于 2012-06-19T08:44:04.630 に答える