C#隐式FTPS (Implicit FTPS)

實現的方式是通過第三方程式庫實現的,當然最主要的是開源且免費,已測試過沒有問題!

目前還沒有直接取得目錄FileInfo list的方法,不過還好可以用GetDirectoryList來取得類似的結果。

可以參考 https://ftps.codeplex.com/

public class ImplicitFtps
    {
        private static readonly string hostName = "199.1*3.***.**";
        private static readonly string userName = "OECRT";
        private static readonly string password = "****";
        private static readonly int port = 1051;


        public FTPSClient Connect()
        {
            FTPSClient client = new FTPSClient();
            client.Connect(hostName, port,
                                      new NetworkCredential(userName, password),
                                      ESSLSupportMode.Implicit,
                                      new RemoteCertificateValidationCallback((a, b, c, d) => { return true; }),
                                      null,
                                      0,
                                      0,
                                      0,
                                      120000,
                                      false,
                                      EDataConnectionMode.Passive);
            return client;
        }


        public void UploadFile(string localFile, string remotePath)
        {   
            using (FTPSClient client = this.Connect())
            {
                if (string.IsNullOrEmpty(remotePath))
                    remotePath = client.GetCurrentDirectory();

                client.SetTransferMode(ETransferMode.Binary);
                client.SetTextEncoding(ETextEncoding.UTF8);
                FileInfo fileInfo = new FileInfo(localFile);
                client.PutFile(localFile, System.IO.Path.Combine(remotePath, fileInfo.Name));
            }
        }

        public IList<DirectoryListItem> GetFiles()
        {
            using (FTPSClient client = this.Connect())
            {
                return client.GetDirectoryList();
            }
        }
    }

 

转载于:https://www.cnblogs.com/milo-xie/p/6399735.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值