ClientFtpDlg.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:19k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // ClientFtpDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "ClientFtp.h"
- #include "ClientFtpDlg.h"
- #include ".clientftpdlg.h"
- #include "MyFtpClient.h"
- #include "MyFtpList.h"
- #include "afxinet.h"
- #include "wininet.h"
- #include "winsock2.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- char mLocalDirectory[MAX_PATH];
- char mServerDirectory[MAX_PATH];
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // CClientFtpDlg 对话框
- CClientFtpDlg::CClientFtpDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CClientFtpDlg::IDD, pParent)
- , m_strPassWord(_T(""))
- , m_strServerAddress(_T(""))
- , m_strUserName(_T(""))
- , m_strMessage(_T(""))
- , m_nPort(0)
- , m_PASV(FALSE)
- , m_bHaveDotFlag(FALSE)
- , m_pDragImageList(NULL)
- , m_fileDirCount(0)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CClientFtpDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_LIST_LOCAL_FILES, m_controlLocalFile);
- DDX_Control(pDX, IDC_LIST_SERVER_FILES, m_controlServerFile);
- DDX_Control(pDX, IDC_COMBO_LOCALDIR, m_controlLocalDir);
- DDX_Control(pDX, IDC_COMBO_SERVERDIR, m_controlServerDir);
- DDX_Text(pDX, IDC_EDIT_ADDRESS, m_strServerAddress);
- DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassWord);
- DDX_Text(pDX, IDC_EDIT_USERNAME,m_strUserName);
- DDX_Text(pDX,IDC_EDIT_PORT,m_nPort);
- DDX_Text(pDX,IDC_EDIT_MASSAGE,m_strMessage);
- DDX_Text(pDX,IDC_CHECK_ANONYMOUS,m_PASV);
- }
- BEGIN_MESSAGE_MAP(CClientFtpDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_CONNECT, OnButtonConnect)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST_LOCAL_FILES, OnNMDblclkListLocalFiles)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST_SERVER_FILES, OnNMDblclkListServerFiles)
- ON_CBN_SELCHANGE(IDC_COMBO_LOCALDIR, OnCbnSelchangeComboLocaldir)
- ON_MESSAGE(WM_SETFILE,CClientFtpDlg::OnInsertLocalFile)
- ON_MESSAGE(WM_SETREDRAWFLAG,CClientFtpDlg::OnSetRedrawFlag)
- ON_MESSAGE(WM_SETDIRECTORYDISPLAY,CClientFtpDlg::OnSetLocalDirDisplay)
- ON_MESSAGE(WM_REDISPLAYFILE,CClientFtpDlg::OnReDisplayLocalFile)
- ON_MESSAGE(WM_SETDIR,CClientFtpDlg::OnSetLocalDir)
- ON_BN_CLICKED(IDCANCEAL, OnBnClickedCanceal)
- END_MESSAGE_MAP()
- // CClientFtpDlg 消息处理程序
- BOOL CClientFtpDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- // TODO: 在此添加额外的初始化代码
- //创建ImageList
- HIMAGELIST himagelist;
- //定义文件信息变量
- SHFILEINFO shfileinfo;
- himagelist=(HIMAGELIST)SHGetFileInfo("C:\",0,&shfileinfo,sizeof(shfileinfo),SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
- //将文件图像列表存入
- m_ctImageList.m_hImageList=himagelist;
- //设定客户端文件显示列表框的标题栏
- SetFileColumns(&m_controlLocalFile);
- //显示服务器端文件显示列表框的标题
- SetServerFileColumns(&m_controlServerFile);
- //设置文件头标信息
- SetImageList(&m_controlLocalFile,&m_controlLocalDir);
- SetImageList(&m_controlServerFile,NULL);
- m_controlLocalFile.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- //获得本地驱动器有关信息,并显示文件信息
- GetLocalDir();
- int i=m_controlLocalDir.FindStringExact(-1,"C:\");
- m_controlLocalDir.SetCurSel(i);
- ::SetCurrentDirectory("C:\");
- GetLocalCurrentDir();
- BeginFindLocalFile();
- //便于调试初始化的登录信息
- m_strServerAddress="211.69.196.53";
- m_nPort=21;
- m_strUserName="book";
- m_strPassWord="book";
- UpdateData(false);
- return TRUE;
- }
- void CClientFtpDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- void CClientFtpDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作矩形中居中
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标显示。
- HCURSOR CClientFtpDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CClientFtpDlg::OnButtonConnect()
- {
- // TODO: Add your control notification handler code here
- WORD wVersionRequested;
- WSADATA wsaData;
- wVersionRequested = MAKEWORD( 2, 2 );
- WSAStartup( wVersionRequested, &wsaData );
- int index=0;
- CString str;
- UpdateData(TRUE);
- m_strMessage=m_strMessage+"连接服务器:"+m_strServerAddress+"rn";
- m_strMessage=m_strMessage+"登录用户名:"+m_strUserName+"rn";
- UpdateData(false);
- if(!ftp.LogOntoServer(m_strServerAddress,m_nPort,m_strUserName,m_strPassWord,"","","","",1080,0))
- {
- m_strMessage=m_strMessage+m_strUserName+"登录失败。"+"rn";
- UpdateData(false);
- return;
- }
- else
- {
- ftp.List();
- while(ftp.GetLine(index))
- {
- AddLine(ftp.m_strLine);
- str="/";
- strcpy(mServerDirectory,str);
- SetServerDir(str);
- }
- ftp.FTPCommand("");
- }
- }
- void CClientFtpDlg::OnNMDblclkListLocalFiles(NMHDR *pNMHDR, LRESULT *pResult)
- {
- // TODO: Add your control notification handler code here
- NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
- CString str,str1,fileName,buffer;
- int iIcon,iIconSel;
- str.Format("%d",pLocInfo->item);
- if(str=="-1")
- return;
- int nItem=atoi(str);
- DWORD dwFlag=m_controlLocalFile.GetItemData(nItem);
- if(dwFlag==FILEICON)
- {
- str=mLocalDirectory;
- m_controlLocalFile.GetItemText(nItem,0,mLocalDirectory,MAX_PATH);
- str1=mLocalDirectory;
- fileName=str1;
- if (str.Right(1)!="\")
- str1=str+"\"+str1;
- else
- str1=str+str1;
- strcpy(mLocalDirectory,str);
- MessageBox("确定要上载文件"+str1+"吗?");
- UpdateData(true);
- UpLoadFile(str1,fileName,m_PASV,false);
- return;
- }
- ::GetCurrentDirectory(MAX_PATH,mLocalDirectory);
- str=mLocalDirectory;
- m_controlLocalFile.GetItemText(nItem,0,mLocalDirectory,MAX_PATH);
- buffer=mLocalDirectory;
- if(str.Right(1)!="\")
- str+="\";
- str+=mLocalDirectory;
- GetFileIcon(buffer,&iIcon,&iIconSel);
- int i=InsertLocalDir(str,iIcon,iIconSel);
- m_controlLocalDir.SetCurSel(i);
- ::SetCurrentDirectory(str);
- ::GetCurrentDirectory(MAX_PATH,mLocalDirectory);
- BeginFindLocalFile();
- *pResult = 0;
- }
- void CClientFtpDlg::OnNMDblclkListServerFiles(NMHDR *pNMHDR, LRESULT *pResult)
- {
- // TODO: Add your control notification handler code here
- NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
- CString str,str1,str2,buffer;
- int pos1=0;
- str.Format("%d",pLocInfo->item);
- if(str=="-1")
- return;
- int nItem=atoi(str);
- DWORD dwFlag=m_controlServerFile.GetItemData(nItem);
- str2=m_controlServerFile.GetItemText(nItem,0);
- if(dwFlag==FILEICON)
- {
- str=mServerDirectory;
- if (str.Right (1)!="/")
- str+="/"+str2;
- else
- str+=str2;
- AfxMessageBox("下载文件:"+str2+"?");
- DownLoadFile(str,str2,m_PASV,true);
- return;
- }
- str=mServerDirectory;
- str1=mServerDirectory;
- if(str.Right (1)!="/")
- str+="/";
- str+=m_controlServerFile.GetItemText(nItem,0);
- str2=m_controlServerFile.GetItemText(nItem,0);
- if(!str2.CompareNoCase(".."))
- {
- if (str1=="/")
- return;
- else
- {
- m_controlServerFile.DeleteAllItems ();
- Back();
- pos1=str1.GetLength ()-1;
- while (pos1>=0)
- { if (str1.Mid (pos1,1)!="/")
- {
- pos1--;
- }
- else
- {
- str=str1.Mid (0,pos1+1);
- break;
- }
- }
- strcpy(mServerDirectory,str);
- SetServerDir(str);
- }
- }
- else
- {
- m_controlServerFile.DeleteAllItems ();
- CD(str);
- strcpy(mServerDirectory,str);
- SetServerDir(str);
- }
- *pResult = 0;
- }
- void CClientFtpDlg::OnCbnSelchangeComboLocaldir()
- {
- // TODO: Add your control notification handler code here
- CString str;
- char lpBuffer[MAX_PATH];
- ::GetCurrentDirectory(MAX_PATH,lpBuffer);
- int i=m_controlLocalDir.GetCurSel();
- m_controlLocalDir.GetLBText(i,(LPTSTR)(LPCTSTR)str);
- i=0;
- while(1)
- {
- if(!SetCurrentDirectory(str))
- {
- i++;
- if(i<2)
- {
- AfxMessageBox("请插入磁盘重试");
- continue;
- }
- str=lpBuffer;
- if((i=m_controlLocalDir.FindStringExact(-1,str))!=-1)
- m_controlLocalDir.SetCurSel(i);
- else
- m_controlLocalDir.SetWindowText(str);
- }
- else
- {
- ::SetCurrentDirectory(str);
- GetLocalCurrentDir();
- BeginFindLocalFile();
- }
- break;
- }
- }
- void CClientFtpDlg::OnInsertFile(CListCtrl* pListCtrl, LPVOID pIn, LPARAM lParam)
- {
- FTP_FILE_INFO *pInfo=(FTP_FILE_INFO*)pIn;
- LVITEM lvItem;
- int iIcon,nItem,iIconSel;
- if(pInfo->n_Type==DIRECTORYICON)
- nItem=0;
- else
- nItem=pListCtrl->GetItemCount();
- CString fileName=pInfo->sFileName;;
- if((int)lParam==LOCFILE)
- GetFileIcon(fileName,&iIcon,&iIconSel);
- else
- iIcon=pInfo->n_Type;
- lvItem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
- lvItem.iImage=iIcon;
- lvItem.lParam=pInfo->n_Type;
- lvItem.pszText=pInfo->sFileName;
- lvItem.iSubItem=0;
- lvItem.iItem=nItem;
- int iPos=pListCtrl->InsertItem(&lvItem);
- lvItem.mask=LVIF_TEXT;
- lvItem.iItem=iPos;
- lvItem.pszText=pInfo->sFileDate;
- lvItem.iSubItem=1;
- pListCtrl->SetItem(&lvItem);
- //m_ctrlLocalFile.SetItem(&lvIt);
- lvItem.pszText=pInfo->sFileSize;
- lvItem.iSubItem=2;
- pListCtrl->SetItem(&lvItem);
- }
- void CClientFtpDlg::GetFileIcon(CString& fileName, int* iIcon, int* iIconSel)
- {
- CString str=fileName;
- if(str.Right(1)!="\")
- str+="\";
- SHFILEINFO shFi;
- if(!SHGetFileInfo(str,0,&shFi,sizeof(shFi),SHGFI_ICON|SHGFI_SMALLICON|SHGFI_DISPLAYNAME))
- {
- AfxMessageBox("打开文件图标出错");
- return;
- }
- *iIcon=shFi.iIcon;
- DestroyIcon(shFi.hIcon);
- if(iIconSel)
- {
- if(!SHGetFileInfo(str,0,&shFi,sizeof(shFi),SHGFI_ICON|SHGFI_SMALLICON|SHGFI_OPENICON|SHGFI_DISPLAYNAME))
- {
- AfxMessageBox("打开文件夹图标出错");
- return;
- }
- *iIconSel=shFi.iIcon;
- DestroyIcon(shFi.hIcon);
- }
- return ;
- }
- BOOL CClientFtpDlg::SetImageList(CListCtrl* pListCtrl, CComboBoxEx* pCombo)
- {
- pListCtrl->SetImageList(&m_ctImageList,LVSIL_SMALL);
- if(!pCombo)
- return TRUE;
- pCombo->SetImageList(&m_ctImageList);
- return TRUE;
- }
- void CClientFtpDlg::SetFileColumns(CListCtrl* pListCtrl)
- {
- TCHAR rgtsz[3][10]={_T("文件名"),
- _T("日期"),
- _T("字节数")};
- LV_COLUMN lvcolumn;
- CRect rect;
- pListCtrl->GetWindowRect(&rect);
- for(int i=0;i<3;i++)
- {
- lvcolumn.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH|LVCF_ORDER;
- lvcolumn.fmt=LVCFMT_LEFT;
- lvcolumn.pszText=rgtsz[i];
- lvcolumn.iSubItem=i;
- lvcolumn.iOrder=i;
- if(i==0)
- {lvcolumn.cx=rect.Width()/3;
- }
- else
- lvcolumn.cx=rect.Width()/3;
- pListCtrl->InsertColumn(i,&lvcolumn);
- }
- }
- void CClientFtpDlg::GetLocalDir(void)
- {
- int iIcon,iIconSel;
- char LpBuffer[MAX_PATH];
- char* ptr;
- CString str;
- m_fileDirCount=0;
- ::GetLogicalDriveStrings(MAX_PATH,LpBuffer);
- ptr=LpBuffer;
- while(*ptr)
- {
- m_fileDirCount++;
- str=ptr;
- GetFileIcon(str,&iIcon,&iIconSel);
- InsertLocalDir(str,iIcon,iIconSel);
- ptr+=strlen(ptr)+1;
- }
- }
- int CClientFtpDlg::InsertLocalDir(CString& str, int iIcon, int iIconSel)
- {
- int nItem=m_controlLocalDir.GetCount();
- COMBOBOXEXITEM Combo;
- Combo.mask=CBEIF_IMAGE|CBEIF_TEXT|CBEIF_SELECTEDIMAGE;
- Combo.iImage=iIcon;
- Combo.iSelectedImage=iIconSel;
- Combo.pszText=(LPTSTR)(LPCTSTR)str;
- Combo.iItem=nItem;
- m_controlLocalDir.InsertItem(&Combo);
- return nItem;
- }
- void CClientFtpDlg::GetLocalCurrentDir(void)
- {
- CString str;
- m_controlLocalDir.GetWindowText(str);
- strcpy(mLocalDirectory,str);
- }
- BOOL CClientFtpDlg::BeginFindLocalFile(void)
- {
- m_controlLocalFile.DeleteAllItems();
- FindLocalFile();
- return TRUE;
- }
- void CClientFtpDlg::FindLocalFile(void)
- {
- FTP_FILE_INFO* pInfo=new FTP_FILE_INFO;
- CFileFind fileFind;
- UINT i=0;
- CTime time;
- BOOL bContinue;
- ::SetCurrentDirectory(mLocalDirectory);
- ::PostMessage(this->m_hWnd ,WM_SETDIRECTORYDISPLAY,0,0);
- bContinue=fileFind.FindFile("*.*");
- CString str;
- while(bContinue)
- {
- bContinue=fileFind.FindNextFile();
- if(fileFind.IsHidden())continue;
- str=fileFind.GetFileName();
- strcpy(pInfo->sFileName,str);
- fileFind.GetLastWriteTime(time);
- str=time.Format("%x");
- strcpy(pInfo->sFileDate,str);
- if(fileFind.IsDirectory())
- {
- strcpy(pInfo->sFileSize,"");
- pInfo->n_Type=DIRECTORYICON;
- ::SendMessage(this->m_hWnd,WM_SETFILE,(WPARAM)pInfo,
- (LPARAM)LOCFILE);
- }
- else
- {
- DWORD i=fileFind.GetLength();
- if(i>1024)
- {
- str.Format("%d",i/1024);
- str+="KB";
- }
- else
- str.Format("%d",i);
- strcpy(pInfo->sFileSize,str);
- pInfo->n_Type=FILEICON;
- ::SendMessage(this->m_hWnd,WM_SETFILE,(WPARAM)pInfo,
- (LPARAM)LOCFILE);
- }
- }
- ::SendMessage(this->m_hWnd,WM_SETREDRAWFLAG,0,0);
- delete pInfo;
- fileFind.Close();
- }
- void CClientFtpDlg::SetServerDir(CString str)
- {
- m_controlServerDir.SetWindowText(str);
- m_controlServerDir.Invalidate();
- }
- void CClientFtpDlg::AddLine(CString strLine)
- {
- MyFtpList* pItemList=new MyFtpList();
- if(!pItemList->ParseLine(strLine))
- {
- delete pItemList;
- return;
- }
- AddItem(pItemList);
- }
- BOOL CClientFtpDlg::AddItem(MyFtpList* pItem)
- {
- LV_ITEM lvitem;//存放所有列表项的变量
- lvitem.lParam = (LPARAM)pItem;
- lvitem.iImage = pItem->GetImage();
- lvitem.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
- int index = m_controlServerFile.GetItemCount ();
- lvitem.pszText = pItem->m_strName.GetBuffer(0);
- pItem->m_strName.ReleaseBuffer();
- lvitem.iItem = index;
- lvitem.iSubItem = 0;
- index=m_controlServerFile.InsertItem( &lvitem );
- lvitem.mask =LVIF_TEXT;
- lvitem.pszText = pItem->m_strDate.GetBuffer(0);
- pItem->m_strDate.ReleaseBuffer();
- lvitem.iItem = index;
- lvitem.iSubItem = 1;
- m_controlServerFile.SetItem( &lvitem );
- lvitem.pszText = pItem->m_strsst.GetBuffer(0);
- pItem->m_strsst.ReleaseBuffer();
- lvitem.iItem = index;
- lvitem.iSubItem = 2;
- m_controlServerFile.SetItem( &lvitem );
- if (pItem->GetImage()==7)
- m_controlServerFile.SetItemData(index,DIRECTORYICON);
- else
- m_controlServerFile.SetItemData(index,FILEICON);
- return (pItem != NULL);
- }
- void CClientFtpDlg::SetServerFileColumns(CListCtrl* pListCtrl)
- {
- TCHAR rgtsz[3][10]={_T("文件名"),
- _T("日 期"),
- _T("权 限")};
- LV_COLUMN lvcolumn;
- CRect rect;
- pListCtrl->GetWindowRect(&rect);
- for(int i=0;i<3;i++)
- {
- lvcolumn.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH|LVCF_ORDER;
- lvcolumn.fmt=LVCFMT_LEFT;
- lvcolumn.pszText=rgtsz[i];
- lvcolumn.iSubItem=i;
- lvcolumn.iOrder=i;
- if(i==0)
- {lvcolumn.cx=rect.Width()/3;
- }
- else
- lvcolumn.cx=rect.Width()/3;
- pListCtrl->InsertColumn(i,&lvcolumn);
- }
- }
- void CClientFtpDlg::CD(CString dir)
- {
- int index=0;
- dir.TrimLeft();
- dir.TrimRight();
- CString cmd = "CWD " + dir;
- ftp.FTPCommand(cmd);
- ftp.FTPCommand("PWD");
- ftp.List();
- while(ftp.GetLine(index))
- {
- UpdateData(false);
- AddLine(ftp.m_strLine );
- }
- ftp.FTPCommand("");
- }
- void CClientFtpDlg::Back(void)
- {
- int index=0;
- ftp.FTPCommand("CDUP");
- ftp.List();
- while(ftp.GetLine(index))
- {
- UpdateData(false);
- AddLine(ftp.m_strLine );
- }
- ftp.FTPCommand("");
- }
- void CClientFtpDlg::UpLoadFile(CString LocalFilePath, CString LocalFileName, bool pasv, bool get)
- {
- CString str;
- str=mServerDirectory;
- if (str.Right(1)!="/")
- str+="/"+LocalFileName;
- else
- str+=LocalFileName;
- ftp.MoveFile (str,LocalFilePath,pasv,get);
- }
- void CClientFtpDlg::DownLoadFile(CString ServerFilePath, CString ServerFileName, bool pasv, bool get)
- {
- CString str;
- str=mLocalDirectory;
- if (str.Right(1)!="\")
- str+="\"+ServerFileName;
- else
- str+=ServerFileName;
- ftp.MoveFile (ServerFilePath,str,pasv,get);
- }
- LRESULT CClientFtpDlg::OnReDisplayLocalFile(WPARAM wParam, LPARAM lParam)
- {
- CString str=(LPCTSTR)wParam;
- m_controlLocalDir.SetWindowText(str);
- m_controlLocalDir.Invalidate();
- GetLocalCurrentDir();
- if(!BeginFindLocalFile())
- AfxMessageBox("连接失败");
- return 0L;
- }
- LRESULT CClientFtpDlg::OnSetLocalDirDisplay(WPARAM wParam, LPARAM lParam)
- {
- CString str;
- str=mLocalDirectory;
- m_controlLocalDir.SetWindowText(str);
- m_controlLocalDir.Invalidate();
- return 0L;
- }
- LRESULT CClientFtpDlg::OnInsertLocalFile(WPARAM wParam,LPARAM lParam)
- {
- FTP_FILE_INFO* pInfo=(FTP_FILE_INFO*)wParam;
- CString str=pInfo->sFileName;
- if(str=="."||str=="..")
- {
- m_bHaveDotFlag=TRUE;
- return 0L;
- }
- OnInsertFile(&m_controlLocalFile,pInfo,lParam);
- return 0L;
- }
- LRESULT CClientFtpDlg::OnSetRedrawFlag(WPARAM wParam, LPARAM lParam)
- {
- if(m_bHaveDotFlag)
- {
- CString str="..";
- int iIcon=DIRECTORYICON;
- m_controlLocalFile.InsertItem(0,str,iIcon);
- m_controlLocalFile.SetItemData(0,DIRECTORYICON);
- m_bHaveDotFlag=FALSE;
- }
- m_controlLocalFile.Invalidate();
- m_controlLocalFile.SetRedraw();
- return 0L;
- }
- LRESULT CClientFtpDlg::OnSetLocalDir(WPARAM wParam, LPARAM lParam)
- {
- CString str=(LPCTSTR)lParam;
- m_controlLocalDir.SetWindowText(str);
- m_controlLocalFile.SetRedraw(FALSE);
- m_controlLocalFile.DeleteAllItems();
- m_controlLocalFile.SetRedraw();
- return 0L;
- }
- void CClientFtpDlg::OnBnClickedCanceal()
- {
- // TODO: Add your control notification handler code here
- ftp.CloseControlChannel();
- UpdateData(TRUE);
- m_strMessage="断开和服务器之间的连接!";
- UpdateData(FALSE);
- m_controlServerDir.SetWindowText("");
- m_controlServerFile.DeleteAllItems();
- }