zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }
  • 相关阅读:
    【回溯】数字排列问题
    Price List
    NanoApe Loves Sequence-待解决
    【回溯】n皇后问题
    安卓 学习之旅 入门
    mysql链接 显示 error: 'Access denied for user 'root'@'localhost' (using password: NO)'
    javaweb 实战_1
    java 插件安装
    leetcode 最长有效括号
    hdu 1074 Doing Homework
  • 原文地址:https://www.cnblogs.com/milo-xie/p/6399735.html
Copyright © 2011-2022 走看看