如何使用MFC在ListBox中显示FTP服务器列表 [英] How to show FTP server list in ListBox using MFC
本文介绍了如何使用MFC在ListBox中显示FTP服务器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用MFC创建FTP服务器客户端.
I want to make an FTP server client using MFC.
服务器连接成功.
如何在列表框中打印FTP服务器文件和目录列表?
How do I print a list of FTP server files and diretory in the list box??
通过一个简单的示例,任何建议都将不胜感激.
Any advice would be appreciated with a simple example.
CInternetSession m_Session;
CFtpConnection* m_pConnection;
CFtpFileFind* m_pFileFind;
CListBox m_List;
CString m_strIP, m_strID, m_strPass;
void CMFC_FTPDlg::ConnectFTP()
{
GetDlgItemText(IDC_EDIT_IP, m_strIP);
GetDlgItemText(IDC_EDIT_ID, m_strID);
GetDlgItemText(IDC_EDIT_PASS, m_strPass);
m_nPort = GetDlgItemInt(IDC_EDIT_PORT);
m_pConnection = m_Session.GetFtpConnection(m_strIP, m_strID, m_strPass, m_nPort);
if(!m_pConnection)
{
AfxMessageBox("ERROR : Disconnected!!");
m_pConnection = NULL;
m_bContinue = FALSE;
return;
}
else
{
AfxMessageBox("Connected!!");
m_bContinue = TRUE;
}
}
void CMFC_FTPDlg::ShowList()
{
int nResult;
nResult = m_pConnection->SetCurrentDirectory("test");
}
推荐答案
根据文档,典型的FTP客户端应用程序中的步骤,您需要使用 FindFile()
和
Per the documentation, Steps in a Typical FTP Client Application, you need to use the CFtpFileFind
class, which has FindFile()
and FindNextFile()
methods for enumerating an FTP server's files.
您已经声明了 CFtpFileFind * m_pFileFind
变量,但是您没有使用它.
You already have a CFtpFileFind* m_pFileFind
variable declared, but you are not using it.
尝试一下:
void CMFC_FTPDlg::ShowList()
{
int nResult;
nResult = m_pConnection->SetCurrentDirectory("test");
CFtpFileFind finder(m_pConnection);
BOOL bWorking = finder.FindFile(_T("*"));
while (bWorking)
{
bWorking = finder.FindNextFile();
// use finder.GetFileURL() or finder.GetFileName() as needed...
}
}
这篇关于如何使用MFC在ListBox中显示FTP服务器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文