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();
                }
            }
        }
  • 相关阅读:
    jquery笔记
    linux的日常经常使用的命令
    IDEA设置类注解和方法注解(详解)
    java读取项目或包下面的属性文件方法
    枚举类的使用
    将一个浮点数转化为人民币大写字符串
    简单五子棋实现
    crontab 设置服务器定期执行备份工作
    linux创建日期文件名
    代码层读写分离实现
  • 原文地址:https://www.cnblogs.com/milo-xie/p/6399735.html
Copyright © 2011-2022 走看看