在程序运行的时候要用ftp方式多次从服务器上下载数据。但不知为何,运行程序,调用(第一次)下面函数下载时能正确完成,但等服务器端文件更新后,第二次调用下载,得到的文件还是更新前的文件。我这段代码有什么问题?请问该如何获得最新的文件?使用代码:
CFtpConnection *pFtpConnection=NULL;
pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
try
{
pFtpConnection=pInetSession->GetFtpConnection(ServerIP);//ServerIP为服务端ip地址
}
catch(CInternetException *pEx)
{
pEx->Delete();
pFtpConnection=NULL;
delete pInetSession;
}
if (!pFtpConnection->SetCurrentDirectory("send"))//“send”为server端FTP共享目录
{
//设置出错
}
else
{
if(!pFtpConnection->GetFile(ServerFileName,LocalFilePathName,false))
{ //ServerFileName为服务端文件名,LocalFilePathName为本地目标文件
//下载出错
}
}
if(pFtpConnection!=NULL)
{
pFtpConnection->Close();
delete pFtpConnection;
}
pInetSession->Close();
delete pInetSession;
CFtpConnection *pFtpConnection=NULL;
pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
try
{
pFtpConnection=pInetSession->GetFtpConnection(ServerIP);//ServerIP为服务端ip地址
}
catch(CInternetException *pEx)
{
pEx->Delete();
pFtpConnection=NULL;
delete pInetSession;
}
if (!pFtpConnection->SetCurrentDirectory("send"))//“send”为server端FTP共享目录
{
//设置出错
}
else
{
if(!pFtpConnection->GetFile(ServerFileName,LocalFilePathName,false))
{ //ServerFileName为服务端文件名,LocalFilePathName为本地目标文件
//下载出错
}
}
if(pFtpConnection!=NULL)
{
pFtpConnection->Close();
delete pFtpConnection;
}
pInetSession->Close();
delete pInetSession;
memset(&serverfilname, 0, siziof(serverfilename));另外,MFC的异常处理里好像不用显式调用delete,我一般都把e->delete去掉!高手请指教!
但是:
以上代码是一个函数的一部分
CString serverfilename是函数内的一个局部变量。我第二次下载的时候重新调用这个函数的,也就是说serverfilename是重新申明的。
另外服务器端文件更新后文件名是不变的,只不过文件内容更新了,第二次下载后得到的文件内容还是更新前的。