FtpFunction.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:40k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // FtpTransmitFile.cpp: implementation of the CFtpTransmitFile class.
- //
- //////////////////////////////////////////////////////////////////////
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "QuickFTP.h"
- #include "FtpFunction.h"
- #include "InputFileNameDlg.h"
- #include "shlwapi.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CFtpFunction::CFtpFunction()
- {
- m_bAskUser = true ;
- m_iWhenExistAction = 0 ;
- }
- CFtpFunction::~CFtpFunction()
- {
- }
- /***********************************************************
- ** @Description:
- ** Send "ABORrn" command to fpt server,
- abord the current data link .
- ** @Parameter:
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::AbordThreadFunction()
- {
- char szCommand[MAX_PATH] ;
- memset( szCommand , 0 , MAX_PATH) ;
- closesocket( m_hDataSocket ) ;
- sprintf( szCommand , "ABORrn" ) ;
- SendFtpCommand( szCommand , m_hControlSocket ) ;
- ClearUpReceiveBuffer( ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** check the ftp server is support broken download.
- **
- ** @Parameter:
- **
- ** @Return: if support return true ,else return false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::CheckBrokenDownload()
- {
- //set type I
- UINT nReplyCode = 0 ;
- nReplyCode = SendFtpCommand( "TYPE Irn" , m_hControlSocket ) ;
- if( nReplyCode != 200 )
- return false ;
- //reset file pointer.
- nReplyCode = SendFtpCommand( "REST 100rn" , m_hControlSocket ) ;
- if( nReplyCode >= 400 )
- return false ;
- if( nReplyCode == 350 )
- {
- m_SiteInfo.brokendownload = true ;
- sprintf( m_szFtpBuffer , _T("站点支持断点续传") ) ;
- SendStatusStr( m_szFtpBuffer ) ;
- }
- else
- {
- m_SiteInfo.brokendownload = false ;
- sprintf( m_szFtpBuffer , _T("站点不支持断点续传") ) ;
- SendStatusStr( m_szFtpBuffer ) ;
- }
- //reset.
- nReplyCode = SendFtpCommand( "REST 0rn" , m_hControlSocket ) ;
- if( nReplyCode >= 400 )
- return false ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** check the ftp server operate system type .
- **
- ** @Parameter:
- **
- ** @Return: if success return true , else return false
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::CheckServerType()
- {
- UINT uReplyCode = 0 ;
- char szBuffer[1024] ;
- int iLength = 0 ;
- //send syst command .
- sprintf( szBuffer , "SYSTrn" ) ;
- if( send( m_hControlSocket , szBuffer , strlen( szBuffer ) , 0 ) == SOCKET_ERROR )
- {
- int iWinsockErr = WSAGetLastError( ) ;
- sprintf( m_szFtpBuffer , " %d error while Send ftp command !" , iWinsockErr ) ;
- MessageBox( NULL , m_szFtpBuffer , MSGBOX_TITLE , MB_OK ) ;
- return ( ERROR_FTP_CODE ) ;
- }
- //Send msg to window .
- SendMsgToParentWnd( szBuffer , true ) ;
- //receive server reply string .
- if( ( iLength = recv( m_hControlSocket , szBuffer , 1024 , 0 ) ) == SOCKET_ERROR )
- {
- int iWinsockErr = WSAGetLastError( ) ;
- sprintf( m_szFtpBuffer , " %d error while recv server reply!" , iWinsockErr ) ;
- MessageBox( NULL , m_szFtpBuffer , MSGBOX_TITLE , MB_OK ) ;
- return ( ERROR_FTP_CODE ) ;
- }
- if( iLength < MAX_PATH )
- szBuffer[ iLength ] = 0 ;
- else
- szBuffer[ MAX_PATH - 1 ] = 0 ;
- //Send msg to window .
- SendMsgToParentWnd( szBuffer , false ) ;
- UINT nReplyCode = GetReplyCode ( szBuffer ) ;
- if( nReplyCode >= 400 || nReplyCode <= 0 )
- return false ;
- if( strstr( szBuffer , "UNIX" ) != NULL )
- {
- m_SiteInfo.hosttype = 1 ;
- }
- else
- {
- if( strstr( szBuffer , _T("Windows_NT") ) != NULL )
- m_SiteInfo.hosttype = 2 ;
- else
- m_SiteInfo.hosttype = 1 ;
- }
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** Because the receive buffer can leave some message,
- so we must clear the receive buffer before
- send another command .
- ** @Parameter:
- ** void
- **
- ** @Return: void
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- void CFtpFunction::ClearUpReceiveBuffer()
- {
- while( true )
- {
- if( !IsReadyToRead( m_hControlSocket ) )
- {
- return ;
- }
- GetServerReply( m_hControlSocket ) ;
- }
- }
- /***********************************************************
- ** @Description:
- ** Create the specify directory in ftp server .
- **
- ** @Parameter:
- ** LPSTR szPath :the directory name which want create.
- **
- ** @Return: if success return true ,else return false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::CreateFtpDirectory(LPCTSTR szPath)
- {
- char szCommand[MAX_PATH] ;
- UINT nReplyCode = 0 ;
- sprintf( szCommand , "MKD %srn" , szPath ) ;
- nReplyCode = SendFtpCommand( szCommand , m_hControlSocket ) ;
- if( nReplyCode >= 400 )
- return false ;
- else
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** transmit file function . this function download or upload
- ** the specify file.
- **
- ** @Parameter:
- ** FTPFILEINFO* pParam : ftp file info.
- **
- ** @Return: success true ,else false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::PutGetFileFunction(FTPFILEINFO *pParam)
- {
- FTPFILEINFO FtpFileInfo ;
- memcpy( &FtpFileInfo , pParam , sizeof( FTPFILEINFO ) ) ;
- UINT nReplyCode ;
- SOCKET hDataSocket ;
- SOCKET hListenSocket ;
- char szCommand[MAX_PATH] ;
- //make full path name ;
- char szPathName[MAX_PATH] ;
- strcpy( szPathName , FtpFileInfo.localpath ) ;
- int iLength = strlen( FtpFileInfo.localpath ) ;
- if( szPathName[iLength-1 ] != '\' )
- {
- szPathName[iLength]= '\' ;
- szPathName[iLength+1] = ' ' ;
- }
- strcat( szPathName , FtpFileInfo.localfilename ) ;
- HANDLE hFile ;
- //open local file ,and set ftp file info.
- hFile = OpenLocalFile( &FtpFileInfo , szPathName ) ;//CreateFile( szPathName , GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , 0 ) ;
- if( hFile == INVALID_HANDLE_VALUE )
- {
- return false ;
- }
- //entry the directory .
- //sprintf( szCommand , "CWD %srn" , pFtpFileInfo->remotepath ) ;
- //nReplyCode = ftp.SendFtpCommand( szCommand , pFtpFileInfo->hSocket ) ;
- //if ( nReplyCode >= 400 )
- // return false ;
- //make the command , is put or get file .
- //if put file to server , send command STOR.
- //if get file from server , send command RETR.
- memset( szCommand , 0 , MAX_PATH );
- /*
- if( FtpFileInfo.site.brokendownload )
- {
- char szTemp[MAX_PATH] ;
- strcpy( szCommand , "REST " ) ;
- _i64toa( FtpFileInfo.startpos , szTemp , 10 ) ;
- strcat( szCommand , szTemp ) ;
- strcat( szCommand , "rn" ) ;
- nReplyCode = SendFtpCommand( szCommand , FtpFileInfo.hSocket ) ;
- if( nReplyCode == 350 )
- MyFileSeek( hFile , FtpFileInfo.startpos , FILE_BEGIN ) ;
- }
- if( FtpFileInfo.bfileput )
- sprintf( szCommand , "STOR %srn" , FtpFileInfo.remotefilename ) ;
- else
- sprintf( szCommand , "APPE %srn" , FtpFileInfo.remotefilename ) ;
- */
- //make the broken transmit pos .
- MakeBrokenPos( szCommand , &FtpFileInfo , hFile ) ;
- //set data type to I.
- nReplyCode = SendFtpCommand( "TYPE Irn" , FtpFileInfo.hSocket ) ;
- if( nReplyCode >= 400 )
- {
- CloseHandle( hFile ) ;
- hFile = INVALID_HANDLE_VALUE ;
- return false ;
- }
- //make the date link
- hListenSocket = CreateListenCannel( FtpFileInfo.hSocket ) ;
- if( hListenSocket == INVALID_SOCKET )
- {
- CloseHandle( hFile ) ;
- hFile = INVALID_HANDLE_VALUE ;
- return false ;
- }
- //send transmit command .
- nReplyCode = SendFtpCommand( szCommand , FtpFileInfo.hSocket ) ;
- if( nReplyCode >= 400 )
- {
- CloseHandle( hFile ) ;
- hFile = INVALID_HANDLE_VALUE ;
- return false ;
- }
- //accept the connected.
- hDataSocket = AcceptDataConnect( hListenSocket ) ;
- if( hDataSocket == INVALID_SOCKET )
- {
- CloseHandle( hFile ) ;
- hFile = INVALID_HANDLE_VALUE ;
- return false ;
- }
- //notify the parent wnd .
- SendFileNameToParentWnd( FtpFileInfo.remotefilename ) ;
- //start transmit.
- if( FtpFileInfo.bfileput )
- nReplyCode = WriteDataCannelFromFile( FtpFileInfo.hSocket , hDataSocket , hFile ) ;
- else
- nReplyCode = ReadDataCannelToFile( FtpFileInfo.hSocket , hDataSocket , hFile , FtpFileInfo.filesize ) ;
- //clear server reply buffer .
- ClearUpReceiveBuffer( ) ;
- closesocket( hListenSocket ) ;
- if( nReplyCode >= 400 || nReplyCode == 0 )
- {
- CloseHandle( hFile ) ;
- return false ;
- }
- m_FileQueue.DeleteItem( pParam ) ;
- return 1 ;
- }
- /***********************************************************
- ** @Description:
- ** this function is upload a directory to ftp server.
- ** this function use recursion arithmetic .
- **
- ** @Parameter:
- ** FTPFILEINFO* pFileInfo : the directory info.
- **
- ** @Return: success true ,else false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::UploadDirectory(FTPFILEINFO *pFileInfo)
- {
- FTPITEM* pItemQueueHead ;
- FTPITEM* pItemCur ;
- FTPFILEINFO FtpFileInfo ;
- char szPathBak[MAX_PATH] ;
- BOOL bRet ;
- //copy the dir info.
- memcpy( &FtpFileInfo , pFileInfo , sizeof( FTPFILEINFO ) ) ;
- //prepare the path .
- if( !MakeFtpUploadPath( &FtpFileInfo ) )
- return false ;
- //backup current path.
- strcpy( szPathBak , m_CurrentFtpDirectory ) ;
- CFileFind find ;
- CString Path = FtpFileInfo.localpath ;
- if( Path.Right( 1 ) != '\' )
- Path += '\' ;
- Path += "*.*" ;
- BOOL bFind = find.FindFile( Path ) ;
- pItemQueueHead = m_ListItem ;
- pItemCur = m_ListItem ;
- while( bFind )
- {
- bFind = find.FindNextFile( ) ;
- if( find.IsDirectory() && !find.IsDots( ) )
- {
- //is directory .
- FtpFileInfo.bfileput = true ;
- FtpFileInfo.bIsDirectory = true ;
- FtpFileInfo.endpos = 0 ;
- FtpFileInfo.startpos = 0 ;
- strcpy( FtpFileInfo.remotefilename , find.GetFileName( ) ) ;
- strcpy( FtpFileInfo.localfilename , find.GetFileName( ) ) ;
- //FtpFileInfo.hSocket = pFileInfo->hSocket ;
- //FtpFileInfo.hWnd = pFileInfo->hWnd ;
- UploadDirectory( &FtpFileInfo ) ;
- EnterFtpDirectory( szPathBak ) ;
- if( !GetCurrentFtpDir() )
- return false ;
- }
- if ( !find.IsDirectory() )
- {
- //is file .
- FtpFileInfo.bfileput = true ;
- FtpFileInfo.bIsDirectory = false ;
- FtpFileInfo.endpos = 0 ;
- //is the file already exist in server?
- FtpFileInfo.startpos = FindFileInFileList( find.GetFileName( ) , pItemCur ) ;
- strcpy( FtpFileInfo.remotefilename , find.GetFileName( ) ) ;
- strcpy( FtpFileInfo.localfilename , find.GetFileName( ) ) ;
- //broken transmit .
- bRet = BrokenDownload( &FtpFileInfo ) ;
- if( !bRet )
- return false ;
- }
- }
- //free the ftp file list.
- FreeItemList( pItemCur ) ;
- m_FileQueue.DeleteItem( pFileInfo ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** the function is download a directory from server.
- ** this function use recursion arithmetic .
- **
- ** @Parameter:
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::DownLoadDirectory(FTPFILEINFO *pFileInfo)
- {
- FTPITEM* pItemQueueHead ;
- FTPITEM* pItemCur ;
- FTPFILEINFO FtpFileInfo ;
- char szPathBak[MAX_PATH] ;
- BOOL bRet = true ;
- memcpy( &FtpFileInfo , pFileInfo , sizeof( FTPFILEINFO ) ) ;
- //prepare the directory .
- if( !MakeFtpDownloadPath( &FtpFileInfo ) )
- return false ;
- //get the current dir .
- if( !GetCurrentFtpDir() )
- return false ;
- //backup current directory.
- strcpy( szPathBak , m_CurrentFtpDirectory ) ;
- if( m_ListItem->pNext == NULL )
- {
- m_FileQueue.DeleteItem( pFileInfo ) ;
- return true ;
- }
- pItemQueueHead = m_ListItem ;
- pItemCur = m_ListItem ;
- while( pItemCur->pNext != NULL )
- {
- //is directory .
- if( pItemCur->dwType == 1 )
- {
- //make directory info.
- FtpFileInfo.bfileput = false ;
- FtpFileInfo.bIsDirectory = true ;
- FtpFileInfo.endpos = 0 ;
- FtpFileInfo.startpos = 0 ;
- strcpy( FtpFileInfo.remotefilename , pItemCur->szName ) ;
- strcpy( FtpFileInfo.localfilename , pItemCur->szName ) ;
- //download directory.
- bRet = DownLoadDirectory( &FtpFileInfo ) ;
- //after download directory, we must recover the directory.
- EnterFtpDirectory( szPathBak ) ;
- if( !bRet )
- return false ;
- }
- else
- {
- FtpFileInfo.bfileput = false ;
- FtpFileInfo.bIsDirectory = false ;
- FtpFileInfo.endpos = 0 ;
- strcpy( FtpFileInfo.remotefilename , pItemCur->szName ) ;
- strcpy( FtpFileInfo.localfilename , pItemCur->szName ) ;
- char szFilePathName[MAX_PATH] ;
- sprintf( szFilePathName , "%s%s" , FtpFileInfo.localpath ,
- FtpFileInfo.localfilename ) ;
- FtpFileInfo.filesize = _atoi64( pItemCur->szSize ) ;
- //find the start pos.
- FtpFileInfo.startpos = FindFileInLocal( szFilePathName ) ;
- bRet = BrokenDownload( &FtpFileInfo ) ;
- if( !bRet )
- return false ;
- }
- pItemCur = pItemCur->pNext ;
- }
- //free the list.
- FreeItemList( pItemQueueHead ) ;
- m_FileQueue.DeleteItem( pFileInfo ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function is perpare the download path .
- **
- ** @Parameter:
- ** FTPFILEINFO* pFileInfo : the download item info.
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::MakeFtpDownloadPath(FTPFILEINFO *pFileInfo)
- {
- int iLength = strlen( pFileInfo->localpath ) ;
- if( pFileInfo->localpath[iLength-1] != '\' )
- {
- pFileInfo->localpath[iLength] = '\' ;
- pFileInfo->localpath[iLength + 1] = ' ' ;
- }
- //make local path.
- strcat( pFileInfo->localpath , pFileInfo->remotefilename ) ;
- strcat( pFileInfo->localpath , "\" ) ;
- //create local path .
- CreateDirectory( pFileInfo->localpath , NULL ) ;
- //make remote path
- iLength = strlen( pFileInfo->remotepath ) ;
- if( pFileInfo->remotepath[iLength-1] != '/' )
- {
- pFileInfo->remotepath[iLength] = '/' ;
- pFileInfo->remotepath[iLength + 1] = ' ' ;
- }
- strcat( pFileInfo->remotepath , pFileInfo->remotefilename ) ;
- strcat( pFileInfo->remotepath , "/" ) ;
- //enter remote path.
- if( !EnterFtpDirectory( pFileInfo->remotepath ) )
- return false ;
- if( !GetCurrentFtpDir() )
- return false ;
- ListDirectory( false ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function is enter specify remote path .
- **
- ** @Parameter:
- ** LPSTR strPath : the remote path.
- **
- ** @Return: success return true ,else return false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::EnterFtpDirectory(LPSTR strPath)
- {
- char szCommand[MAX_PATH] ;
- UINT nReplyCode = 0 ;
- //make command .
- sprintf( szCommand , "CWD %srn" , strPath ) ;
- //send command .
- nReplyCode = SendFtpCommand( szCommand , m_hControlSocket ) ;
- if( nReplyCode >= 400 )
- return false ;
- else
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function is free the ftp file queue.
- **
- ** @Parameter:
- ** FTPITEM* pFtpItem :the file queue head pointer.
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::FreeItemList(FTPITEM * pFtpItem )
- {
- FTPITEM * pNextItem = pFtpItem ;
- FTPITEM * pCurItem = pFtpItem ;
- while( pNextItem != NULL )
- {
- pCurItem = pNextItem ;
- pNextItem = pNextItem->pNext ;
- try
- {
- delete pCurItem ;
- }
- catch(...)
- {
- TRACE( "memory delete error!" ) ;
- }
- pCurItem = NULL ;
- }
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function is prepare the upload directory.
- **
- ** @Parameter:
- ** FTPFILEINFO* pFileInfo : the ftp file info.
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::MakeFtpUploadPath(FTPFILEINFO* pFileInfo )
- {
- int iLength = strlen( pFileInfo->localpath ) ;
- //make local path.
- if( pFileInfo->localpath[iLength-1] != '\' )
- {
- pFileInfo->localpath[iLength] = '\' ;
- pFileInfo->localpath[iLength + 1] = ' ' ;
- }
- strcat( pFileInfo->localpath , pFileInfo->localfilename ) ;
- iLength = strlen( pFileInfo->remotepath ) ;
- //create the fpt directory ,
- //we needn't to chech the success or not .
- CreateFtpDirectory( pFileInfo->remotefilename ) ;
- strcat( pFileInfo->localpath , "\" ) ;
- //make remote path.
- if( pFileInfo->remotepath[iLength-1] != '/' )
- {
- pFileInfo->remotepath[iLength] = '/' ;
- pFileInfo->remotepath[iLength + 1] = ' ' ;
- }
- strcat( pFileInfo->remotepath , pFileInfo->localfilename ) ;
- //enter remote path.
- if( !EnterFtpDirectory( pFileInfo->remotepath ) )
- return false ;
- strcat( pFileInfo->remotepath , "/" ) ;
- if( !GetCurrentFtpDir() )
- return false ;
- ListDirectory( false ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function list the current directory , and get
- ** current directory file list.
- ** @Parameter:
- ** BOOL bWantSend : is want send list to parent wnd ?
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::ListDirectory( BOOL bWantSend )
- {
- SOCKET hDataSocket ;
- SOCKET hListenSocket ;
- int nReplyCode = 0 ;
- //make the status .
- //sprintf( m_szFtpBuffer , "刷新文件列表rn" ) ;
- //SendStatusStr( m_szFtpBuffer ) ;
- nReplyCode = SendFtpCommand( "TYPE Arn" , m_hControlSocket ) ;
- if( nReplyCode >= 400 || nReplyCode <= 0 )
- return false ;
- hListenSocket = CreateListenCannel( m_hControlSocket ) ;
- if( hListenSocket == INVALID_SOCKET )
- return false ;
- nReplyCode = SendFtpCommand( "LISTrn" , m_hControlSocket ) ;
- if( nReplyCode >= 400 || nReplyCode <= 0 )
- return false ;
- //now let UI wait the thread receive list data complete .
- char* pStr ;
- pStr = new char[1];
- pStr[0] = ' ' ;
- ::PostMessage( m_hWndInfo.hInfoWnd , FTP_SEND_COMMAND_MSG , 0 , (LPARAM)pStr );
- //accept the server connect socket .
- hDataSocket = AcceptDataConnect( hListenSocket ) ;
- m_hDataSocket = hDataSocket ;
- if( hDataSocket == INVALID_SOCKET )
- return false ;
- //send status msg
- sprintf( m_szFtpBuffer , "接收文件目录列表....." ) ;
- SendStatusStr( m_szFtpBuffer ) ;
- //read the data from the data link.
- nReplyCode = ReadDataCannel( m_hControlSocket , hDataSocket , bWantSend ) ;
- if( nReplyCode >= 400 || nReplyCode <= 0 )
- return false ;
- closesocket( hListenSocket ) ;
- hListenSocket = INVALID_SOCKET ;
- //send status msg.
- sprintf( m_szFtpBuffer , "接收完毕" ) ;
- SendStatusStr( m_szFtpBuffer ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function is get current ftp directory.
- **
- ** @Parameter:
- ** void
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::GetCurrentFtpDir()
- {
- char szBuffer[MAX_PATH] ;
- int iLength = 0 ;
- //make command .
- sprintf( szBuffer , "PWDrn" ) ;
- if( !m_bRun )
- return ERROR_FTP_CODE ;
- //send command.
- if( send( m_hControlSocket , szBuffer , strlen( szBuffer ) , 0 ) == SOCKET_ERROR )
- {
- int iWinsockErr = WSAGetLastError( ) ;
- sprintf( m_szFtpBuffer , " %d error while Send ftp command !" , iWinsockErr ) ;
- MessageBox( NULL , m_szFtpBuffer , MSGBOX_TITLE , MB_OK ) ;
- return ( ERROR_FTP_CODE ) ;
- }
- SendMsgToParentWnd( szBuffer , true ) ;
- // AfxMessageBox( szBuffer ) ;
- //peek the message .
- if( ( iLength = recv( m_hControlSocket , szBuffer , 1024 , MSG_PEEK ) ) == SOCKET_ERROR )
- {
- int iWinsockErr = WSAGetLastError( ) ;
- sprintf( m_szFtpBuffer , " %d error while recv server reply!" , iWinsockErr ) ;
- MessageBox( NULL , m_szFtpBuffer , MSGBOX_TITLE , MB_OK ) ;
- //return ( ERROR_FTP_CODE ) ;
- }
- int iBuffer = 0 ;
- while( szBuffer[iBuffer] != 'n' )
- {
- iBuffer ++ ;
- if( iBuffer >= iLength )
- break ;
- }
- iBuffer ++ ;
- //add by table 2001 4 24
- //test recv in win98
- //iBuffer = MAX_PATH ;
- //receive server reply string .
- if( ( iLength = recv( m_hControlSocket , szBuffer , iBuffer , 0 ) ) == SOCKET_ERROR )
- {
- int iWinsockErr = WSAGetLastError( ) ;
- sprintf( m_szFtpBuffer , " %d error while recv server reply!" , iWinsockErr ) ;
- MessageBox( NULL , m_szFtpBuffer , MSGBOX_TITLE , MB_OK ) ;
- return ( ERROR_FTP_CODE ) ;
- }
- if( iLength < MAX_PATH )
- szBuffer[ iLength ] = 0 ;
- else
- szBuffer[ MAX_PATH - 1 ] = 0 ;
- //Send msg to window .
- SendMsgToParentWnd( szBuffer , false ) ;
- UINT nReplyCode = GetReplyCode ( szBuffer ) ;
- if( nReplyCode >= 400 || nReplyCode <= 0 )
- return false ;
- //Get return path string .
- //the server reply string include the current path .
- CString strFind = szBuffer ;
- int StartPos = 0 ;
- int EndPos = 0 ;
- memset( m_CurrentFtpDirectory , 0 , sizeof( m_CurrentFtpDirectory) ) ;
- if( ( StartPos =strFind.Find( """ , 0 ) ) == -1 )
- return true ;
- StartPos ++ ;
- if( ( EndPos = strFind.Find ( """ , StartPos ) ) == -1 )
- return true ;
- strFind = strFind.Mid( StartPos , EndPos - StartPos ) ;
- strcpy( m_CurrentFtpDirectory , (LPCTSTR)strFind ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** read data from cannel.
- **
- ** @Parameter:
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- UINT CFtpFunction::ReadDataCannel(SOCKET hControlSocket, SOCKET hDataSocket , BOOL bWantSend )
- {
- DWORD nByteRec = 0 ;
- DWORD lDataNum = 0 ;
- char ReceiveBuffer[64] ;
- //use CString class to store the data
- CString strBuffer ;
- strBuffer.Empty() ;
- do
- {
- memset( ReceiveBuffer , 0 , sizeof( ReceiveBuffer ) ) ;
- nByteRec = recv( hDataSocket , ReceiveBuffer , 63 , 0 ) ;
- if( nByteRec == SOCKET_ERROR )
- break ;
- if( nByteRec > 0 )
- {
- ReceiveBuffer[nByteRec] = 0 ;
- lDataNum = nByteRec + lDataNum ;
- strBuffer += ReceiveBuffer ;
- //display the receive bytes .
- m_szFtpBuffer[0] = ' ' ;
- sprintf( m_szFtpBuffer , "接收到的字节数: %d" , lDataNum ) ;
- //TRACE( "%d - %d rn " , lDataNum , nByteRec ) ;
- SendFileNameToParentWnd( m_szFtpBuffer ) ;
- }
- }
- while( nByteRec > 0 );
- //clear the display bytes .
- sprintf( m_szFtpBuffer , " " ) ;
- SendFileNameToParentWnd( m_szFtpBuffer ) ;
- SendFileNameToParentWnd( m_szFtpBuffer ) ;
- //strBuffer.SetAt( lDataNum , ' ' ) ;
- //parse the directory .
- ParseDirectroyInfo( strBuffer , bWantSend );
- closesocket( hDataSocket ) ;
- hDataSocket = NULL ;
- m_hDataSocket = NULL ;
- if( nByteRec == SOCKET_ERROR )
- return false ;
- if( lDataNum == 0 )
- return ( GetServerReply( hControlSocket ) ) ;
- return ( GetServerReply( hControlSocket ) ) ;
- }
- /***********************************************************
- ** @Description:
- **
- ** @Parameter:
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- void CFtpFunction::ParseDirectroyInfo(CString buffer , BOOL bWantSend )
- {
- /*
- AfxMessageBox( buffer ) ;
- CFile file ;
- file.Open( "e:\abc.txt" , CFile::modeCreate|CFile::modeWrite ) ;
- file.Write( (LPCTSTR)buffer , buffer.GetLength() ) ;
- file.Close() ;
- */
- int EndPos = 0 ;
- FTPITEM* pFtpItemHead ;
- FTPITEM* pFtpItem ;
- FTPITEM* pCurItem ;
- char szBuffer[MAX_PATH] ;
- int iRet = 0 ;
- pFtpItem = new FTPITEM ;
- memset( pFtpItem , 0 , sizeof( FTPITEM ) ) ;
- CString pLine ;
- pFtpItemHead = pFtpItem ;
- pCurItem = pFtpItem ;
- //choose the server type .
- switch( m_SiteInfo.hosttype )
- {
- case UNIX_SERVER :
- //skip the first line .
- while( iRet != 2 && EndPos < buffer.GetLength() )
- {
- iRet = GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- }
- while( EndPos < buffer.GetLength() )
- {
- iRet = 0 ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szAttrib , szBuffer ) ;
- if( szBuffer[0] == 'd' )
- pCurItem->dwType = 1 ;
- else
- pCurItem->dwType = 0 ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szSize , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szDate , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcat( pCurItem->szDate , " " ) ;
- strcat( pCurItem->szDate , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szTime , szBuffer ) ;
- while( iRet != 2 && EndPos < buffer.GetLength() )
- {
- iRet = GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcat( pCurItem->szName , szBuffer ) ;
- if( iRet != 2 )
- strcat( pCurItem->szName , " " ) ;
- }
- pFtpItem = new FTPITEM ;
- //pFtpItem->pNext = NULL ;
- memset ( pFtpItem , 0 , sizeof( FTPITEM ) ) ;
- pCurItem->pNext = pFtpItem ;
- pCurItem = pFtpItem ;
- }
- break ;
- case WINNT_SERVER :
- while( EndPos < buffer.GetLength() )
- {
- iRet = 0 ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szDate , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szTime , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- if( strcmp( szBuffer , "<DIR>" ) == 0 )
- {
- pCurItem->dwType = 1 ;
- strcpy( pCurItem->szSize , "" ) ;
- }
- else
- {
- pCurItem->dwType = 0 ;
- strcpy( pCurItem->szSize , szBuffer ) ;
- }
- while( iRet != 2 && EndPos < buffer.GetLength() )
- {
- iRet = GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcat( pCurItem->szName , szBuffer ) ;
- if( iRet != 2 )
- strcat( pCurItem->szName , " " ) ;
- }
- strcpy( pCurItem->szAttrib, "" ) ;
- pFtpItem = new FTPITEM ;
- //pFtpItem->pNext = NULL ;
- memset ( pFtpItem , 0 , sizeof( FTPITEM ) ) ;
- pCurItem->pNext = pFtpItem ;
- pCurItem = pFtpItem ;
- }
- break ;
- case LINUX_SERVER :
- {
- iRet = 0 ;
- while( iRet != 2 && EndPos < buffer.GetLength() )
- {
- iRet = GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- }
- while( EndPos < buffer.GetLength() )
- {
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szAttrib , szBuffer ) ;
- if( szBuffer[0] == 'd' )
- pCurItem->dwType = 1 ;
- else
- pCurItem->dwType = 0 ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szSize , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szDate , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcat( pCurItem->szDate , " " ) ;
- strcat( pCurItem->szDate , szBuffer ) ;
- GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcpy( pCurItem->szTime , szBuffer ) ;
- while( iRet != 2 && EndPos < buffer.GetLength() )
- {
- iRet = GetSubItem( &EndPos , szBuffer , MAX_PATH , &buffer ) ;
- strcat( pCurItem->szName , szBuffer ) ;
- if( iRet != 2 )
- strcat( pCurItem->szName , " " ) ;
- }
- pFtpItem = new FTPITEM ;
- //pFtpItem->pNext = NULL ;
- memset ( pFtpItem , 0 , sizeof( FTPITEM ) ) ;
- pCurItem->pNext = pFtpItem ;
- pCurItem = pFtpItem ;
- }
- }
- break ;
- default:
- break;
- }
- if( bWantSend )
- {
- ::PostMessage( m_hWndInfo.hFtpDirListWnd , FTP_SERVER_DIR_LIST_MSG , (WPARAM)pFtpItemHead , 0 ) ;
- }
- else
- {
- m_ListItem = pFtpItemHead ;
- }
- }
- /***********************************************************
- ** @Description:
- ** delete a file in ftp server .
- **
- ** @Parameter:
- ** LPSTR szFileName : the delete file name .
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::DeleteFtpFile(LPSTR szFileName)
- {
- char szCommand[MAX_PATH] ;
- UINT uReplyCode = 0 ;
- sprintf( szCommand , "DELE %srn" , szFileName ) ;
- uReplyCode = SendFtpCommand( szCommand , m_hControlSocket ) ;
- if( uReplyCode > 400 )
- return false ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function delete a directory in ftp server .
- ** this function use recursion arithmetic .
- **
- ** @Parameter:
- ** FTPFILEINFO* pFileInfo : the delete directory info .
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::DeleteFtpDirectory(FTPFILEINFO *pFileInfo)
- {
- FTPITEM* pItemQueueHead ;
- FTPITEM* pItemCur ;
- FTPFILEINFO FtpFileInfo ;
- char szPathBak[MAX_PATH] ;
- memcpy( &FtpFileInfo , pFileInfo , sizeof( FTPFILEINFO ) ) ;
- if( !MakeFtpDownloadPath( &FtpFileInfo ) )
- return false ;
- if( !GetCurrentFtpDir() )
- return false ;
- strcpy( szPathBak , m_CurrentFtpDirectory ) ;
- pItemQueueHead = m_ListItem ;
- pItemCur = m_ListItem ;
- if( m_ListItem->pNext == NULL )
- {
- FreeItemList( pItemQueueHead ) ;
- return false ;
- }
- while( pItemCur->pNext != NULL )
- {
- if( pItemCur->dwType == 1 )
- {
- FtpFileInfo.bfileput = false ;
- FtpFileInfo.bIsDirectory = true ;
- FtpFileInfo.endpos = 0 ;
- FtpFileInfo.startpos = 0 ;
- strcpy( FtpFileInfo.remotefilename , pItemCur->szName ) ;
- strcpy( FtpFileInfo.localfilename , pItemCur->szName ) ;
- //FtpFileInfo.hSocket = pFileInfo->hSocket ;
- //FtpFileInfo.hWnd = pFileInfo->hWnd ;
- DeleteFtpDirectory( &FtpFileInfo ) ;
- EnterFtpDirectory( szPathBak ) ;
- RemoveFtpDirectory( FtpFileInfo.remotefilename ) ;
- }
- else
- {
- DeleteFtpFile( pItemCur->szName ) ;
- }
- pItemCur = pItemCur->pNext ;
- }
- FreeItemList( pItemQueueHead ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** this function remove a directory in ftp server .
- **
- ** @Parameter:
- ** LPSTR szDirName : the dir name .
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::RemoveFtpDirectory(LPSTR szDirName)
- {
- char szCommand[MAX_PATH] ;
- UINT uReplyCode = 0 ;
- sprintf( szCommand , "RMD %srn" , szDirName ) ;
- uReplyCode = SendFtpCommand( szCommand , m_hControlSocket ) ;
- if( uReplyCode > 400 )
- return false ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** Find file in remote file list .
- **
- ** @Parameter
- ** LPCTSTR szFileName : the file name .
- ** FTPITEM* pFileList : remote file list.
- **
- ** @Return: the broken transmit position .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- __int64 CFtpFunction::FindFileInFileList(LPCTSTR szFileName, FTPITEM *pFileList)
- {
- FTPITEM* pCur ;
- __int64 iSize = 0 ;
- if( pFileList == NULL )
- return 0 ;
- pCur = pFileList ;
- while( pCur->pNext != NULL )
- {
- if( strcmp( szFileName , pCur->szName ) == 0 )
- {
- //is want ask user ?
- if( m_bAskUser )
- {
- char szPathName[MAX_PATH] ;
- sprintf( szPathName , "%s/%s" , m_CurrentFtpDirectory , szFileName ) ;
- m_SelActionDlg.m_strPathName = szPathName ;
- m_SelActionDlg.DoModal( ) ;
- m_bAskUser = !m_SelActionDlg.m_bAsk ;
- m_iWhenExistAction = m_SelActionDlg.m_iAction ;
- }
- iSize = _atoi64( pCur->szSize ) ;
- switch( m_iWhenExistAction )
- {
- case 1 :
- //overlay
- {
- iSize = 0 ;
- }
- break ;
- case 2 :
- //resume
- break ;
- case 3 :
- //rename
- iSize = 0 ;
- break ;
- case 4 :
- //skip
- break ;
- default :
- break ;
- }
- return iSize ;
- }
- pCur = pCur->pNext ;
- }
- return 0 ;
- }
- /****************************************************
- ** @Description
- ** find file in local .
- **
- ** @Parameter
- ** LPCTSTR szPathName : the file path name .
- **
- ** @Return: the broken transmit position .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- __int64 CFtpFunction::FindFileInLocal(LPCTSTR szPathName)
- {
- __int64 iSize = 0 ;
- TRACE( "%s---%drn" , szPathName , m_bAskUser ) ;
- if( PathFileExists( szPathName ) )
- {
- TRACE( "%s---%drn" , szPathName , m_bAskUser ) ;
- if( m_bAskUser )
- {
- m_SelActionDlg.m_strPathName = szPathName ;
- m_SelActionDlg.DoModal( ) ;
- m_bAskUser = !m_SelActionDlg.m_bAsk ;
- m_iWhenExistAction = m_SelActionDlg.m_iAction ;
- }
- HANDLE hFile = CreateFile( szPathName , GENERIC_READ | GENERIC_WRITE ,
- FILE_SHARE_READ , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , 0 ) ;
- if( hFile == INVALID_HANDLE_VALUE )
- return 0 ;
- DWORD dwlSize ;
- DWORD dwhSize ;
- dwlSize = GetFileSize( hFile , &dwhSize ) ;
- iSize = dwhSize ;
- iSize = iSize << 32 ;
- iSize += dwlSize ;
- switch( m_iWhenExistAction )
- {
- case 1 :
- //overlay
- {
- iSize = 0 ;
- }
- break ;
- case 2 :
- //resume
- break ;
- case 3 :
- //rename
- iSize = 0 ;
- break ;
- case 4 :
- //skip
- break ;
- default :
- break ;
- }
- CloseHandle( hFile ) ;
- return iSize ;
- }
- else
- {
- //char dis[500] ;
- //sprintf(
- //AfxMessageBox( "Can't Find File ! " ) ;
- //AfxMessageBox( szPathName ) ;
- }
- return iSize ;
- }
- /****************************************************
- ** @Description
- **
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CFtpFunction::BrokenDownload( FTPFILEINFO *pFile)
- {
- BOOL bRet = true ;
- switch( m_iWhenExistAction )
- {
- case 4 :
- {
- break ;
- }
- case 3 :
- //rename
- {
- CInputFileNameDlg dlg ;
- dlg.DoModal( ) ;
- if( pFile->bfileput )
- strcpy( pFile->remotefilename , dlg.m_strName ) ;
- else
- strcpy( pFile->localfilename , dlg.m_strName ) ;
- }
- case 1 :
- case 2 :
- default :
- {
- //strcpy( pFile->localfilename , pItemCur->szName ) ;
- pFile->iExistAction = m_iWhenExistAction ;
- bRet = PutGetFileFunction( pFile ) ;
- }
- break ;
- }
- return bRet ;
- }
- /****************************************************
- ** @Description
- ** open the file with the specify file info.
- **
- ** @Parameter
- ** FTPFILEINFO* pFile : file info
- ** LPCTSTR szPathName : the file path name .
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- HANDLE CFtpFunction::OpenLocalFile(FTPFILEINFO *pFile, LPCTSTR szPathName)
- {
- HANDLE hFile ;
- if( !pFile->bfileput )
- {
- switch( pFile->iExistAction )
- {
- case 2 ://resume transmit .
- hFile = CreateFile( szPathName , GENERIC_READ | GENERIC_WRITE ,
- FILE_SHARE_READ , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , 0 ) ;
- break ;
- default :
- hFile = CreateFile( szPathName , GENERIC_READ | GENERIC_WRITE ,
- FILE_SHARE_READ , NULL , CREATE_ALWAYS , FILE_ATTRIBUTE_NORMAL , 0 ) ;
- break ;
- }
- }
- else
- {
- hFile = CreateFile( szPathName , GENERIC_READ | GENERIC_WRITE ,
- FILE_SHARE_READ , NULL , OPEN_ALWAYS , FILE_ATTRIBUTE_NORMAL , 0 ) ;
- if( hFile == INVALID_HANDLE_VALUE )
- {
- DWORD dwErr = GetLastError( ) ;
- }
- }
- return hFile ;
- }
- /****************************************************
- ** @Description
- ** prepare the broken transmit , move to
- ** broken position .
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CFtpFunction::MakeBrokenPos(char *szCommand, FTPFILEINFO *pFile , HANDLE hFile )
- {
- UINT nReplyCode = 0 ;
- if( pFile->site.brokendownload )
- {
- char szTemp[MAX_PATH] ;
- strcpy( szCommand , "REST " ) ;
- _i64toa( pFile->startpos , szTemp , 10 ) ;
- strcat( szCommand , szTemp ) ;
- strcat( szCommand , "rn" ) ;
- //send rest command.
- nReplyCode = SendFtpCommand( szCommand , pFile->hSocket ) ;
- if( nReplyCode == 350 )
- MyFileSeek( hFile , pFile->startpos , FILE_BEGIN ) ;
- }
- if( pFile->bfileput )
- {
- switch( pFile->iExistAction )
- {
- case 2 :
- //append the data to exist file .
- sprintf( szCommand , "APPE %srn" , pFile->remotefilename ) ;
- break ;
- default :
- sprintf( szCommand , "STOR %srn" , pFile->remotefilename ) ;
- break ;
- }
- }
- else
- sprintf( szCommand , "RETR %srn" , pFile->remotefilename ) ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** send current transmit file name to parent wnd .
- **
- ** @Parameter
- ** LPCTSTR szName : file name .
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CFtpFunction::SendFileNameToParentWnd(LPCTSTR szName)
- {
- char * pName ;
- int iLength = strlen( szName ) ;
- pName = new char[iLength + 1] ;
- strcpy( pName , szName ) ;
- pName[iLength] = ' ' ;
- PostMessage( m_hParentWnd , SEND_TRANSMIT_FILENAME_MSG , (WPARAM)pName , 0 ) ;
- return true;
- }
- /****************************************************
- ** @Description
- ** send status info to parent wnd .
- **
- ** @Parameter
- ** char* pText : status string .
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- void CFtpFunction::SendStatusStr(char *pText)
- {
- char* pSend ;
- int iLength = strlen( pText ) ;
- if( pText[iLength-2] != 'r' )
- strcat( pText , "rn" ) ;
- iLength = strlen( pText ) ;
- //the alloc memory will delete in parent window.
- pSend = new char[iLength + 16];
- strcpy( pSend , "STATUS> " ) ;
- strcat( pSend , pText ) ;
- PostMessage( m_hWndInfo.hInfoWnd , FTP_STATUS_MSG , 0 , (LPARAM)pSend ) ;
- }
- /***********************************************************
- ** @Description:
- ** this public function is used for chech is connected
- ** with ftp server .
- **
- ** @Note:
- **
- ** @Return: if connected return true ,else return false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- *************************************************************/
- BOOL CFtpFunction::IsConnect()
- {
- return m_bIsConnected ;
- }