CFtpConnection哪个成员函数会执行FTP LIST动作

shedawei 2018-06-13 07:25:35



SetCurrentDirectory 设置当前FTP目录
GetCurrentDirectory 获取此次连接的当前目录
GetCurrentDirectoryAsURL 获取作为URL的此次连接的当前目录
RemoveDirectory 从服务器移去指定目录
CreateDirectory 在服务器上构造一个目录
Rename 将服务器上的文件改名
Remove 从服务器上移去一个文件
PutFile 将一个文件放到服务器上
GetFile 从连接的服务器上获取一个文件
OpenFile 在连接的服务器上打开一个文件
Close 关闭与服务器的连接



下面这个函数哪一步会执行FTP LIST动作???

bool CMTView::Upload_FTP_Daily_Record_Excel_File(const wchar_t * wcp_Excel_File_Path)
{
//
BOOL bFlag;
CInternetSession * p_InternetSession = NULL;
CFtpConnection * p_FtpConnection = NULL;
CString cstrCurrDir, cstrNewCurrDir, csFile_Name;

//
try
{
//提取文件名
if (this->m_cla_GFC.Get_FileName_From_FilePath(wcp_Excel_File_Path, true, &csFile_Name) == false)
{
this->Show_REdit_Info(_T("[INFO]Get Log File Name failed"), true);
throw(1);
}

//connect to ftp
try
{
//创建一个CInternetSession对象
p_InternetSession = new CInternetSession();

//创建CFtpConnection对象并返回一个指向该对象的指针
p_FtpConnection = p_InternetSession->GetFtpConnection(
this->m_csFTP_LOG_Server,
this->m_csFTP_LOG_User_Name,
this->m_csFTP_LOG_Password,
this->m_iFTP_LOG_Port, true);
}
catch (CInternetException * pEx)//error:can not connect to specific ftp
{
//fail
this->Show_REdit_Info(_T("[INFO]Connect to FTP failed"), true);
//
if (p_FtpConnection != NULL)
{
delete p_FtpConnection;
p_FtpConnection = NULL;
}
if (p_InternetSession != NULL)
{
delete p_InternetSession;
p_InternetSession = NULL;
}

//建立FTP连接失败
throw(2);
}

//设置FTP路径"TestLog"
cstrNewCurrDir.Format(_T("//TestLog/"));
//
bFlag = p_FtpConnection->SetCurrentDirectory(cstrNewCurrDir);
//
if (bFlag != TRUE)//set current directory error
{
//this->Show_REdit_Msg(_T("ERROR, SetCurrentDirectory( TestLog ) is fail!"), true);
//fail
this->Show_REdit_Info(_T("[INFO]Set FTP TestLog Directory failed"), true);
throw(3);
}

//设置当前目录SetCurrentDirectory,失败就创建目录CreateDirectory,还失败就关闭ftp返回错误
//设置FTP路径"年份"
cstrNewCurrDir.Format(_T("//TestLog/%s/"), this->m_csMO_Create_Year);
//
bFlag = p_FtpConnection->SetCurrentDirectory(cstrNewCurrDir);
//
if (bFlag != TRUE)//set current directory error
{
//创建年份路径
//create directory on ftp
bFlag = p_FtpConnection->CreateDirectory(cstrNewCurrDir);
//
if (bFlag == TRUE)//create directory on ftp success
{
//设置FTP路径"年份"
bFlag = p_FtpConnection->SetCurrentDirectory(cstrNewCurrDir);
//
if (bFlag != TRUE)//set current directory error
{
this->Show_REdit_Info(_T("[INFO]Set FTP Year Directory failed"), true);
throw(4);
}


}
else
{
this->Show_REdit_Info(_T("[INFO]Create FTP Year Directory failed"), true);
//fail
throw(5);
}
}

//设置当前目录SetCurrentDirectory,失败就创建目录CreateDirectory,还失败就关闭ftp返回错误
//设置FTP路径"MO"
cstrNewCurrDir.Format(_T("//TestLog/%s/%s/"), this->m_csMO_Create_Year, this->m_dlg_Config.m_csMO_Name);
//
bFlag = p_FtpConnection->SetCurrentDirectory(cstrNewCurrDir);
//
if (bFlag != TRUE)//set current directory error
{
//创建MO路径
//create directory on ftp
bFlag = p_FtpConnection->CreateDirectory(cstrNewCurrDir);
//
if (bFlag == TRUE)//create directory on ftp success
{
//设置FTP路径"MO"
bFlag = p_FtpConnection->SetCurrentDirectory(cstrNewCurrDir);
//
if (bFlag != TRUE)//set current directory error
{
this->Show_REdit_Info(_T("[INFO]Set FTP MO Directory failed"), true);
throw(4);
}


}
else
{
this->Show_REdit_Info(_T("[INFO]Create FTP MO Directory failed"), true);
//fail
throw(5);
}
}

//设置FTP路径"Write"
cstrNewCurrDir.Format(_T("//TestLog/%s/%s/Write/"), this->m_csMO_Create_Year, this->m_dlg_Config.m_csMO_Name);
//
bFlag = p_FtpConnection->SetCurrentDirectory(cstrNewCurrDir);
//
if (bFlag != TRUE)//set current directory error
{
//创建RF_FT路径
//create directory on ftp
bFlag = p_FtpConnection->CreateDirectory(cstrNewCurrDir);
//
if (bFlag == TRUE)//create directory on ftp success
{
//设置FTP路径"RF_FT"
bFlag = p_FtpConnection->SetCurrentDirectory(cstrNewCurrDir);
//
if (bFlag != TRUE)//set current directory error
{
this->Show_REdit_Info(_T("[INFO]Set FTP Write Directory failed"), true);
throw(6);
}

}
else
{
this->Show_REdit_Info(_T("[INFO]Create FTP Write Directory failed"), true);
//fail
throw(7);
}
}

//upload file to ftp
bFlag = p_FtpConnection->PutFile(wcp_Excel_File_Path, csFile_Name);
if (bFlag != TRUE) //upload file fail
{
this->Show_REdit_Info(_T("[INFO]Upload log file to ftp failed"), true);
//fail
throw(8);
}
//
cstrNewCurrDir.Format(_T("[PASS]Upload file(%s) to ftp"), csFile_Name);
this->Show_REdit_Info(cstrNewCurrDir, true);

//断开FTP
if (p_FtpConnection != NULL)
{
p_FtpConnection->Close();
//delete
delete p_FtpConnection;
p_FtpConnection = NULL;
}
if (p_InternetSession != NULL)
{
delete p_InternetSession;
p_InternetSession = NULL;
}
}
catch (int iErr)
{
//断开FTP
if (p_FtpConnection != NULL)
{
p_FtpConnection->Close();
//delete
delete p_FtpConnection;
p_FtpConnection = NULL;
}
if (p_InternetSession != NULL)
{
delete p_InternetSession;
p_InternetSession = NULL;
}

//fail
return false;
}

//pass
return true;
}
...全文
764 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2018-06-15
  • 打赏
  • 举报
回复
还以为你要手动执行FTP LIST 要知道list是哪来的,把FTP指令和你的代码对比下看看list之前执行到了哪一步就行了。cd=SetCurrentDirectory,mkdir=CreateDirectoy之类。
shedawei 2018-06-14
  • 打赏
  • 举报
回复
上面图片里是LIST Check,实际我上面的代码跑出来是LIST Write
shedawei 2018-06-14
  • 打赏
  • 举报
回复
引用 1 楼 jiangsheng 的回复:
CFtpFileFind

我代码里没有用到CFtpFileFind 函数啊,现在就上面那个函数跑下来IT部门说有FTP LIST动作,说是浪费网络资源让优化,但是我无从下手

赵4老师 2018-06-14
  • 打赏
  • 举报
回复
一切以wireshark抓包结果为准!
蒋晟 2018-06-13
  • 打赏
  • 举报
回复
CFtpFileFind

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧