• 一个好用的封装好的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();
    }
  • 相关阅读:
    [luogu1594]护卫队(dp)
    [luogu1968]美元汇率(dp)
    [NOIP2006]金明的预算方案(dp)
    [caioj1056](相同数列问题)填满型01背包2
    [IPUOJ]混合背包 (dp)
    趣说倍增算法
    [POI2005]BAN-Bank Notes (dp、倍增)
    NOIP考前注意
    SharePoint 2013 App 开发—Auto Hosted 方式
    SharePoint 2013 App 开发—App开发概述
  • 原文地址:https://www.cnblogs.com/nanzhi/p/9234970.html
Copyright © 2020-2023  润新知