18,356
社区成员
发帖
与我相关
我的任务
分享
void CFtpTestDlg::OnBnClickedBtnRemoveDir()
{
// TODO: Add your control notification handler code here
CInternetSession mysession;
CFtpConnection* pFtpConn = mysession.GetFtpConnection(_T("10.122.52.79"),_T("xux"),_T("123456"),21,false);
if(pFtpConn)
{
CString downloadFtpPath(_T("17"));
CFtpFileFind finder(pFtpConn);
BOOL res = RemoveFtpDir(downloadFtpPath,finder,pFtpConn);
finder.Close();
}
}
BOOL CFtpTestDlg::RemoveFtpDir(LPCTSTR pstrDirName,CFtpFileFind& finder,CFtpConnection* pFtpConn)
{
CString csFile = pstrDirName + CString(_T("/*.*"));
BOOL bRes = finder.FindFile(csFile);
while(bRes)
{
bRes = finder.FindNextFile();
if (!finder.IsDots())
{
CString filePath = finder.GetFilePath();//那个syscfg卡片机.ini文件变成了17/syspic/syscfg鍗$墖鏈?ini
if (finder.IsDirectory())
{
finder.Close();
if (!RemoveFtpDir(filePath,finder,pFtpConn))
return FALSE;
if (bRes)
bRes = finder.FindFile(csFile);
}
else
{
if (!pFtpConn->Remove(filePath))//有一些中文乱码路径可以删除成功,有些失败
{
WCHAR buffer[128];
DWORD length = 128;
InternetGetLastResponseInfo(&dwError,buffer,&length);//这里获取的错误是:550 File not found
}
}
}
}
if (!pFtpConn->RemoveDirectory(pstrDirName))
{
return FALSE;
}
return TRUE;
}