|
楼主 |
发表于 2006-6-22 16:18
|
显示全部楼层
哈哈,不用担心, 半途而废不是我的风格.只是最近比较忙,所以没时间顾上而已,今天又回来啦..
OK,在上一部分中,我讲客户端获得了远程的文件列表,接下来就进对远程文件列表的操作吧.
远程文件显示在一个列表控件里面,双击其中的一个项,作出反应.如果是目录,就进入目录,如果是文件就把文件下载到本地.
- void CMyFtp2Dlg::OnNMDblclkYourlist(NMHDR *pNMHDR, LRESULT *pResult)
- {
- CString name;
- CString size;
- int row = m_YourList.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED); //取得被双击列表项
- name = m_YourList.GetItemText( row, 0 ); //取得列表项的文件名字段
- size = m_YourList.GetItemText( row, 1 ); //取得列表项的长度字段
- int pos;
- int length = atoi( size );
- CMessage msg;
- msg.m_Type = 0; //设置传输类型,
- if( length == 0 ) //当长度为0时,判断为目录,单击了远程目录,当然是进入那个目录,浏览下面的文件.
- {
- if( name == "." )
- m_RemotePath = "";
- else if( name == ".." )
- {
- m_RemotePath.TrimRight( '/' );
- pos = m_RemotePath.ReverseFind( '/' );
- if( pos > -1 )
- m_RemotePath = m_RemotePath.Left( pos ) + "/";
- else
- m_RemotePath = "";
- }
- else
- m_RemotePath += name + "/";
- msg.m_Content = "cd " + m_RemotePath; //生成取得远程文件列表的命令
- }
- else
- msg.m_Content = "get " + m_RemotePath + name; //生成取得远程文件到本地的命令
- if( !m_ClientTransfer.SendMessage( &msg ) ) //发送命令
- AfxMessageBox( "命令发送失败" );
- *pResult = 0;
- }
复制代码
应该说,这个文件传输程序的下载功能就到这里了.
下载功能完成了,上传功能也就简单了,只是发送的方向不同而已,看代码:
- void CMyFtp2Dlg::OnNMDblclkMylist(NMHDR *pNMHDR, LRESULT *pResult)
- {
- CString name;
- CString size;
- int row = m_MyList.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED);
- name = m_MyList.GetItemText( row, 0 );
- size = m_MyList.GetItemText( row, 1 );
-
- int pos;
- int length = atoi( size );
- if( length == 0 )
- {
- if( name == "." )
- m_CurrentPath = m_DefaultPath;
- else if( name == ".." )
- {
- m_CurrentPath.TrimRight( '/' );
- pos = m_CurrentPath.ReverseFind( '/' );
- m_CurrentPath = m_CurrentPath.Left( pos ) + "/";
- }
- else
- {
- m_CurrentPath += name + "/";
- }
- if( m_CurrentPath.GetLength() < m_DefaultPath.GetLength() )
- m_CurrentPath = m_DefaultPath;
- FillMyList( m_CurrentPath );
- }
- else
- {
- if( m_ClientTransfer.SendFile( m_CurrentPath + name, m_RemotePath + name ) )
- AfxMessageBox( name + " 发送成功" );
- else
- AfxMessageBox( name + " 发送失败" );
- }
- *pResult = 0;
- }
复制代码
跟下载文件的差不多,就不多解释了.
好滴,整个框架就这么完成了.
问题是,现在还有一些细节没有提到,
1,如何响应命令
2,如何发送文件
3,如何接受文件
这三个问题, 留待下回分解. |
|