在用户输入服务器IP地址等信息后
单击“连接服务器”按钮
程序根据用户提供的信息对服务器进行连接
消息响应函数的代码
void CFTPDlg::OnConnect()
{
CString str,str1; //定义字符串变量
int port=0; //定义端口变量
this->GetDlgItem(IDC_EDIT1)->GetWindowText(str); //获取ip字符串
this->GetDlgItem(IDC_EDIT2)->GetWindowText(str1); //获取端口号码
port=(int)atoi(str1); //将端口字符串转换成数字
if(ftp.FTPConnect(str,port)) //调用CFtp对象的函数进行连接
{
this->GetDlgItem(IDC_EDIT5)->SetWindowText("连接成功!"); //通知用户连接状态
this->GetDlgItem(IDC_Connect)->EnableWindow(false);
//连接成功后,设置连接按钮为失效状态
ftp.Send("LIST/r/n"); //发送命令获取文件列表信息
str=ftp.Recv(); //接收数据
ftp.GetFileStatu(str.GetAt(0)); //获取文件名称
}
}