CFtpFileFind的问题 [转] [原]

本文介绍CFtpFileFind类的一个使用限制——无法连续使用两次,并提供了一种通过递归方式删除FTP服务器上文件夹的具体实现方案。

CFtpFileFind 不能使用两次,也就是说,在递归查询的时候,要采用别的方式。
MSDN这样解释:
ERROR_FTP_TRANSFER_IN_PROGRESS
The requested operation cannot be made on the FTP session handle because an
operation is already in progress.

//--------------以下为FtpClient删除文件夹的函数--递归方式-------------
BOOL CysDelFtpFile(LPCTSTR lpStrFile)
{
 CString strFile;
 strFile = lpStrFile;
 strFile.TrimRight("/";
 strFile += "/*.*";

 CFtpFileFind ftpFinder(m_pFtpConnect);
 if(!ftpFinder.FindFile(strFile))
 {
  ftpFinder.Close();
  return FALSE;
 }
 BOOL bFinish = TRUE;
 list<CString> listDirName;
 while(bFinish)
 {
  bFinish = ftpFinder.FindNextFile();
  if(ftpFinder.IsDots())
   continue;
  if(ftpFinder.IsDirectory())
  {
   CString strDir;
   strDir.Format("%s/%s", lpStrFile, ftpFinder.GetFileName());
   listDirName.push_back(strDir);

  }
  else
  {
   m_pFtpConnect->Remove(ftpFinder.GetFilePath());
  }
 }
 ftpFinder.Close();
 CString strDir;

//---这一段照搬了csdn上一位大侠的方法-------
 while(listDirName.size() != 0)
 {
  strDir = *listDirName.begin();
  listDirName.pop_front();
  CysDelFtpFile(strDir);
  m_pFtpConnect->RemoveDirectory(strDir);
 }
 return TRUE;
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值