您的位置:首页 > 编程语言 > PHP开发

FTP断点续传

2016-05-04 15:03 501 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: