xin
August 13th, 2009, 10:58 AM
Hello,
I have a problem about CFtpConnection's GetFile function. Can anyone help me?
I try to get a compressed file from a ftp server by using CFtpConnection::GetFile(). When the file size is not large, it works. But when the file size is larger than 1GB, sometimes it works and sometimes fails. I used GetLastError() and found that the error is 12002 (timeout). I can use the web browser to download those files successfully. So I suppose that the server is fine and something is wrong in the code.
This is the code.
CFtpConnection *pFtpConnection = NULL;
CInternetSession session;
try
{
pFtpConnection = session.GetFtpConnection("ftp.xxx", NULL,NULL,
INTERNET_INVALID_PORT_NUMBER);
}
catch(CInternetException *pEx)
{
AfxMessageBox("Connection failed.");
pFtpConnection = NULL;
pEx->Delete();
}
BOOL bSetFtpDir = pFtpConnection->SetCurrentDirectory(sFtpDirName);
if(!bSetFtpDir)
{
AfxMessageBox("Setting failed.");
session.Close();
pFtpConnection->Close();
delete pFtpConnection;
}
BOOL bDownload = pFtpConnection->GetFile("File.zip",sZipFilePath, TRUE, FILE_ATTRIBUTE_COMPRESSED, FTP_TRANSFER_TYPE_BINARY,1);
if (!bDownload)
{
AfxMessageBox("Downloading failed.");
session.Close();
pFtpConnection->Close();
delete pFtpConnection;
}
session.Close();
pFtpConnection->Close();
delete pFtpConnection;
Did I missing something in the code?
Any help will be appreciated.
I have a problem about CFtpConnection's GetFile function. Can anyone help me?
I try to get a compressed file from a ftp server by using CFtpConnection::GetFile(). When the file size is not large, it works. But when the file size is larger than 1GB, sometimes it works and sometimes fails. I used GetLastError() and found that the error is 12002 (timeout). I can use the web browser to download those files successfully. So I suppose that the server is fine and something is wrong in the code.
This is the code.
CFtpConnection *pFtpConnection = NULL;
CInternetSession session;
try
{
pFtpConnection = session.GetFtpConnection("ftp.xxx", NULL,NULL,
INTERNET_INVALID_PORT_NUMBER);
}
catch(CInternetException *pEx)
{
AfxMessageBox("Connection failed.");
pFtpConnection = NULL;
pEx->Delete();
}
BOOL bSetFtpDir = pFtpConnection->SetCurrentDirectory(sFtpDirName);
if(!bSetFtpDir)
{
AfxMessageBox("Setting failed.");
session.Close();
pFtpConnection->Close();
delete pFtpConnection;
}
BOOL bDownload = pFtpConnection->GetFile("File.zip",sZipFilePath, TRUE, FILE_ATTRIBUTE_COMPRESSED, FTP_TRANSFER_TYPE_BINARY,1);
if (!bDownload)
{
AfxMessageBox("Downloading failed.");
session.Close();
pFtpConnection->Close();
delete pFtpConnection;
}
session.Close();
pFtpConnection->Close();
delete pFtpConnection;
Did I missing something in the code?
Any help will be appreciated.