zoukankan      html  css  js  c++  java
  • 一个好用的封装好的FTPClient

    来源: 

    https://www.codeproject.com/Articles/8667/FTP-Client-Class


    将上面文章中的FTPClient文件夹中添加到自己工程时还需要添加:
    #pragma comment (lib, "Ws2_32.lib")

    否则会有连接错误

    下面仅贴出例子:

    void TestFTP()
    {
       nsFTP::CFTPClient ftpClient;
       nsFTP::CLogonInfo logonInfo(_T("localhost"), 21, _T("anonymous"),
                                               _T("<a href="mailto:anonymous@user.com">anonymous@user.com"));
    
       // connect to server
       ftpClient.Login(logonInfo);
    
       // get directory listing
       nsFTP::TFTPFileStatusShPtrVec list;
       ftpClient.List(_T("/"), list);
    
       // iterate listing
       for( nsFTP::TFTPFileStatusShPtrVec::iterator it=list.begin();
                                                it!=list.end(); ++it )
           TRACE(_T("
    %s"), (*it)->Name().c_str());
    
       // do file operations
       ftpClient.DownloadFile(_T("/pub/test.txt"), _T("c:\temp\test.txt"));
    
       ftpClient.UploadFile(_T("c:\temp\test.txt"), _T("/upload/test.txt"));
    
       ftpClient.Rename(_T("/upload/test.txt"), _T("/upload/NewName.txt"));
    
       ftpClient.Delete(_T("/upload/NewName.txt"));
    
       // disconnect
       ftpClient.Logout();
    }
    
    void TestFXP()
    {
       nsFTP::CFTPClient ftpClientSource;
       nsFTP::CLogonInfo logonInfoSource(_T("sourceftpserver"), 21, _T("anonymous"),
                                                           _T("<a href="mailto:anonymous@user.com">anonymous@user.com"));
    
       nsFTP::CFTPClient ftpClientTarget;
       nsFTP::CLogonInfo logonInfoTarget(_T("targetftpserver"), 21, _T("anonymous"),
                                                           _T("<a href="mailto:anonymous@user.com">anonymous@user.com"));
    
       // connect to server
       ftpClientSource.Login(logonInfoSource);
       ftpClientTarget.Login(logonInfoTarget);
    
    
       // do file operations
       nsFTP::CFTPClient::TransferFile(ftpClientSource, _T("/file.txt"),
                                       ftpClientTarget, _T("/newFile.txt"));
    
    
       // disconnect
       ftpClientTarget.Logout();
       ftpClientSource.Logout();
    }
    
    
    void TestDownloadAsciiFileIntoTextBuffer()
    {
       nsFTP::CFTPClient ftpClientSource;
       nsFTP::CLogonInfo logonInfoSource(_T("sourceftpserver"), 21, _T("anonymous"),
                                                           _T("<a href="mailto:anonymous@user.com">anonymous@user.com</a>"));
    
       // connect to server
       ftpClientSource.Login(logonInfoSource);
    
       nsFTP::COutputStream outputStream(_T("
    "), _T("Example"));
    
       // do file operations
       ftpClientSource.DownloadFile(_T("/file.txt"), outputStream,
                                    nsFTP::CRepresentation(nsFTP::CType::ASCII()));
    
       tstring output = outputStream.GetBuffer();
    
       // disconnect
       ftpClientSource.Logout();
    }
  • 相关阅读:
    windows 开发 数据模版 Itemtemp
    windows 8 获取用户账号信息
    从客户端中检测到有潜在危险的 Request.Form 值解决方法
    asp.net异步处理
    知道web.config 中的 urlMappings怎么用?
    .net c#日期时间函数大全
    设计模式学习心得之工厂类模式(一)简单工厂模式
    远程网页内容抓取
    TreeView数据绑定的方法(1)
    URLRewriter.dll asp.net伪静态
  • 原文地址:https://www.cnblogs.com/nanzhi/p/9234970.html
Copyright © 2011-2022 走看看