最近因客户FTP 升级,将之前的FTP 升级为FTPS,就是ftp连接加密,加密方法是用SSL 加密。

方案一 使用第三方工具

     是用Flashxp 工具自定义Schedure, 实现自动上传功能。缺点:1.目标文件需另外生成,有时间间隔,无法达到及时上传。2.对于上传失败无法做出处理,虽然有log但仍旧有文件丢失。

方案二 使用DLL

    引用AlexPilotti.FTPS.Client 到目标程序中,使用以下方法上传:

          
 

               using (FTPSClient client = new FTPSClient())
                {
                    NetworkCredential netCredential = new NetworkCredential(this._UserName, this._PassWord);
                    client.Connect(
                        this._strHostName,
                        21,
                        netCredential,
                        ESSLSupportMode.All,
                        new System.Net.Security.RemoteCertificateValidationCallback(delegate
                        {
                            return true;
                        }), null, 0, 0, 0, null);
                    Console.WriteLine(client.WelcomeMessage);
                    string remoteCurrentPath = client.GetCurrentDirectory();
                    IList<AlexPilotti.FTPS.Common.DirectoryListItem> list = client.GetDirectoryList(remoteCurrentPath);
                    flag = client.PutFile(Path.Combine(_strSourthDir, fileName), _strDir + Path.GetFileName(fileName));
                   
               Log.Write(string.Format("upload {0} to {1} success!,Transferred bytes count:{2} bytes", fileName, _strDir + Path.GetFileName(fileName),flag.ToString()));
                file.Move(fileName, _strSourthDir, _strBackDir);
                Thread.Sleep(1);

 

posted on 2013-05-14 14:13  lanniao  阅读(2116)  评论(0编辑  收藏  举报