FTP断点续传

来源:互联网 发布:mysql列转行函数 编辑:程序博客网 时间:2024/05/08 03:37

花了一天的时间整出来这点东西,写一下吧!

VOID FtpThief::Connect(TCHAR*IP,TCHAR*USER,TCHAR*PASS,UINT PORT) {pInternetSession = new CInternetSession("MR",INTERNET_OPEN_TYPE_PRECONFIG);try{pFtpConnection = pInternetSession->GetFtpConnection(IP,USER,PASS,PORT);pFtpConnection->CreateDirectory("web\\uploadfile");  bconnect=TRUE;}catch(CInternetException* pEx){TCHAR szErr[1024];pEx->GetErrorMessage(szErr, 1024);printf("错误:%s\n",szErr);pEx->Delete();}}//获取FTP上文件大小 LONGLONG  FtpThief::GetFtpFileSize(CFtpConnection* pFtpCon, CString strFtpFile){ CFtpFileFind   ftpFind(pFtpCon);  LONGLONG filelen = 0; if(ftpFind.FindFile(strFtpFile))  {  ftpFind.FindNextFile();  filelen =   ftpFind.GetLength();  }  ftpFind.Close();  return filelen;}  //断点续传bool FtpThief::FtpTransProc(TCHAR*FilePath,TCHAR*FileName){CString m_ftpPath = FileName;CFile localFile;DWORD nRet = localFile.Open(FilePath,CFile::modeRead|CFile::shareDenyRead);if(!nRet){OutputDebugString("open file error");return false;}//获取文件大小,设置续传文件的位置long long llFileBegin;llFileBegin = GetFtpFileSize(pFtpConnection,m_ftpPath);localFile.Seek(llFileBegin,CFile::begin);///pFtpConnection->CreateDirectory(m_ftpPath);  //是指路径:如FTP://file1/file2.rar 则是"file1//file2.rar"    CInternetFile *pInetFile = NULL;pInetFile=pFtpConnection->Command("APPE " +m_ftpPath,CFtpConnection::CmdRespWrite);DWORD len;long long m_nFileTransSize = 0;char buffer[MAX_PATH*1024*2] = {0};DWORD nBufSize = MAX_PATH*1024*2;//读写文件while(len=localFile.Read(buffer,nBufSize)){pInetFile->Write(buffer,len);m_nFileTransSize += len;}localFile.Close();return true;}


 

原创粉丝点击