C++实现向FTP上传文件

时间:2014-05-10 09:31:12   收藏:0   阅读:635

连接

    CInternetSession *m_pInetsession;  
    CFtpConnection *m_pFtpConnection;  
    m_pInetsession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);  
    try  
    {  
         m_pFtpConnection=m_pInetsession->GetFtpConnection("127.0.0.1",NULL,NULL,38);  
         MessageBox("连接成功");  
    }  
    catch(CInternetException *pEx)  
    {  
        TCHAR szError[1024];  
        if(pEx->GetErrorMessage(szError,1024))  
            AfxMessageBox(szError);  
        else  
            AfxMessageBox("There was an exception");  
        pEx->Delete();  
        m_pFtpConnection=NULL;  
        return;  
    }  

 


下载文件

BOOL GetFile( LPCTSTRpstrRemoteFile, LPCTSTRpstrLocalFile, BOOLbFailIfExists = TRUE, DWORDdwAttributes = FILE_ATTRIBUTE_NORMAL, DWORDdwFlags = FTP_TRANSFER_TYPE_BINARY, DWORDdwContext = 1 );

pstrRemoteFile

A pointer to a null-terminated string containing the name of a file to retrieve from the FTP server.

pstrLocalFile

A pointer to a null-terminated string containing the name of the file to create on the local system.

bFailIfExists

Indicates whether the file name may already be used by an existing file. If the local file name already exists, and this parameter isTRUE,GetFile fails. Otherwise, GetFile will erase the existing copy of the file.

dwAttributes

Indicates the attributes of the file. This can be any combination of the following FILE_ATTRIBUTE_* flags.

dwFlags

Specifies the conditions under which the transfer occurs. This parameter can be any of thedwFlags values described inFtpGetFile in thePlatform SDK.

dwContext

The context identifier for the file retrieval. See Remarks for more information aboutdwContext.

  1. m_pFtpConnection->GetFile("1.txt","D:\\1.txt",false,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY,1)  

删除服务器上的文件

BOOL Remove( LPCTSTR pstrFileName );

Return Value

Nonzero if successful; otherwise 0. If the call fails, the Win32 functionGetLastError may be called to determine the cause of the error.

Parameters

pstrFileName

A pointer to a string containing the file name to remove.

  1. m_pFtpConnection->Remove("1.txt")  

上传文件

BOOL PutFile( LPCTSTR pstrLocalFile, LPCTSTRpstrRemoteFile, DWORDdwFlags = FTP_TRANSFER_TYPE_BINARY, DWORDdwContext = 1 );

Return Value

Nonzero if successful; otherwise 0. If the call fails, the Win32 functionGetLastError may be called to determine the cause of the error.

Parameters

pstrLocalFile

A pointer to a string containing the name of the file to send from the local system.

pstrRemoteFile

A pointer to a string containing the name of the file to create on the FTP server.

dwFlags

Specifies the conditions under which the transfer of the file occurs. Can be any of the FTP_TRANSFER_* constants described inOpenFile.

dwContext

The context identifier for placing the file. See Remarks for more information aboutdwContext.

  1. m_pFtpConnection->PutFile("D:\\3.txt","3.txt",FTP_TRANSFER_TYPE_BINARY,1) 

C++实现向FTP上传文件,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!