使用CFtpFileFind的FindFile函数,找不到已经存在的文件夹
我用CFtpFileFind的FindFile函数查看FTP服务器上根目录下是否已经存在某个同名目录
奇怪的是,在试过的很多台机器中,有一台当查找的目录存在且是空目录时,FindFile返回的是FALSE,而如果这个目录不空时,查找返回TRUE
暂时只在一台机器上出现了这个问题,不理解是什么回事
为此特意写了个段简单的代码,先建立一个空目录,然后查找该目录是否存在,结果还是返回FALSE
不明白原因,希望有大侠能帮忙
代码如下
#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <stdio.h>
#include <string>
CString m_host = "192.168.1.187"; //ftp地址
CString m_username = "user";//用户名
CString m_password = "upfile";//密码
int m_port = 21;//端口
CInternetSession *m_pInetSession;//WinInet类之一,创建并初始化Internet会话
CFtpConnection *m_pFtpConnection;//建立Ftp连接
m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
try
{
m_pFtpConnection=m_pInetSession->GetFtpConnection(m_host,m_username,m_password,m_port);
}
catch(...)
{
m_pFtpConnection=NULL;
}
if(m_pFtpConnection!=NULL)
{
string folder = "2009-4-4";
LPCTSTR Url = folder.c_str();
CFtpFileFind finder(m_pFtpConnection);
BOOL res=finder.FindFile(_T(url));
res = m_pFtpConnection->CreateDirectory(url);
if (res == TRUE)
{
AfxMessageBox("创建目录成功!");
}
else
{
AfxMessageBox("创建目录失败!");
}
res = finder.FindFile(url);
if (res == TRUE)
{
AfxMessageBox("查找成功!");
}
else
{
AfxMessageBox("查找失败!");
}
finder.Close();
m_pFtpConnection->Close();
delete m_pFtpConnection;
delete m_pInetSession;
}