📄 ftpclientdlg.cpp
字号:
LVITEM *pItem = new LVITEM;
pItem->iItem = 0;
pItem->iImage = psfi->iIcon;
pItem->mask = CBEIF_IMAGE|CBEIF_TEXT|CBEIF_SELECTEDIMAGE;
pItem->iSubItem = 0;
strFileName = filefind.GetFileName();
strcpy(cFileName,strFileName);
pItem->pszText = cFileName;
this->m_lstLocalFile.InsertItem(pItem);
pItem->iItem = 0;
pItem->mask = CBEIF_TEXT;
pItem->iSubItem = 1;
filefind.GetCreationTime(tFileDate);
strFileName = tFileDate.Format( " %B %d %Y" );
strcpy(cFileName,strFileName);
pItem->pszText = cFileName;
this->m_lstLocalFile.SetItem(pItem);
pItem->iItem = 0;
pItem->mask = CBEIF_TEXT;
pItem->iSubItem = 2;
nFileLenth = filefind.GetLength();
strFileName.Format ("%d",nFileLenth);
strcpy(cFileName,strFileName);
pItem->pszText = cFileName;
this->m_lstLocalFile.SetItem(pItem);
//delete pItem;
DestroyIcon(psfi->hIcon);
delete pItem;
}
delete psfi;
}
void CftpclientDlg::OnCbnSelchangeCmbLocalfile()
{
// TODO: 在此添加控件通知处理程序代码
CString strLocal;
//CString strLocalDir;
char cLocal[MAX_PATH];
this->UpdateData(TRUE);
this->m_cmbLocalFile.GetWindowText(strLocal);
strcpy(cLocal,strLocal);
if(!::SetCurrentDirectory(cLocal))
{
::AfxMessageBox("设备没有准备好!");
this->m_cmbLocalFile.SetCurSel(0);
this->m_cmbLocalFile.GetWindowText(strLocal);
strcpy(cLocal,strLocal);
}
m_strLocalFile = cLocal;
m_strLocalFile.Trim();
if(m_strLocalFile.Right(1) != "\\")
m_strLocalFile += "\\";
this->SetLocalLst(cLocal);
}
void CftpclientDlg::OnBnClickedButtonConnect()
{
// TODO: 在此添加控件通知处理程序代码
//this->MessageBox ("sssss");
CString strMsg;
this->UpdateData(true);
if (this->m_strAdress == "")
{
this->SetMsg("写入地址!");
return;
}
else
{
strMsg = "地址: " + this->m_strAdress;
this->SetMsg(strMsg);
}
if (!this->m_nPort)
{
this->m_nPort = 21;
this->SetMsg("使用端口21");
}
else
{
strMsg.Format("端口: %d",this->m_nPort);
this->SetMsg(strMsg);
}
if (this->m_strUserName == "")
{
strMsg = "匿名登录!";
this->SetMsg(strMsg);
}
if(!m_FtpClient.LogOnToserver(this->m_strAdress,this->m_nPort,this->m_strUserName,this->m_strPsw))
{
strMsg = "登录失败!";
this->SetMsg(strMsg);
return;
}
strMsg = "登录成功......";
this->SetMsg(strMsg);
bIsLog = TRUE;
//登录成功
this->SetServerCmb(NULL,TRUE);
this->SetServerLst();
}
void CftpclientDlg::OnNMDblclkListLocalfile(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
CString strFileName,strFileDir;
NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
CString str;
str.Format("%d",pLocInfo->item);
if(str=="-1")
return;
int nItem=atoi(str);
strFileName = m_lstLocalFile.GetItemText(nItem,0);
strFileDir = m_strLocalFile + strFileName;
//this->MessageBox(strFileDir);
CFileFind find;
if(!find.FindFile(strFileDir)) return;
find.FindNextFile();
if (find.IsDirectory() == TRUE)
{
//如果是文件夹,改变文件
char cFile[MAX_PATH];
strcpy(cFile,strFileDir);
this->SetLocalCmb(cFile,FALSE);
this->SetLocalLst(cFile);
}
else
{
//如果是文件,上传
if (bIsLog)
{
m_proFileSpeed.SetWindowText("正在上传");
this->m_proFileSpeed.SetRange(0,find.GetLength());
m_FtpClient.MoveFile(strFileName,strFileDir,m_bIsPsv,FALSE);
m_proFileSpeed.SetPos(0);
this->SetServerLst();
}
else
{
::AfxMessageBox("你还没有登录!");
}
}
*pResult = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 函数:SetPos()
//
// 描述:
// 主要是对话框中的进度条进行设置.用以显示上传或下载速度.是在CFClient中调用的
//
//
// 参数:
// -pos 进度条的当前位置
//
//
// 返回:
//
// -无
//
// 吴庆民 2005.5.4
///////////////////////////////////////////////////////////////////////////////////////////////////////
void CftpclientDlg::SetPos(int pos)
{
m_proFileSpeed.SetPos(pos);
}
void CftpclientDlg::SetServerCmb(LPSTR pszPath,BOOL bIsInit)
{
if (bIsInit)
{
COMBOBOXEXITEM CBItem;
CBItem.iItem = 0;
CBItem.pszText = "";
CBItem.iImage = 0;
CBItem.iSelectedImage = 0;
CBItem.mask = CBItem.mask =CBEIF_IMAGE|CBEIF_TEXT|CBEIF_SELECTEDIMAGE;
m_cmbServerFile.InsertItem(&CBItem);
m_cmbServerFile.SetCurSel(0);
}
else
{
COMBOBOXEXITEM CBItem;
char cPath[MAX_PATH];
strcpy(cPath,pszPath);
CBItem.iItem = 0;
CBItem.pszText = cPath;
CBItem.iImage = 0;
CBItem.iSelectedImage = 0;
CBItem.mask = CBItem.mask =CBEIF_IMAGE|CBEIF_TEXT|CBEIF_SELECTEDIMAGE;
m_cmbServerFile.InsertItem(&CBItem);
m_cmbServerFile.SetCurSel(0);
}
}
void CftpclientDlg::SetServerLst()
{
CString str;
int nFileLenth;
LVITEM *pItem = new LVITEM;
char cStr[MAX_PATH];
if (!bIsLog) return;
m_FtpClient.List();
m_lstServerFile.DeleteAllItems();
FTP_FILE_INFO file;
int ndx = 1;
while(1)
{
if(!m_FtpClient.GetFtpFileInfo(ndx,file)) break;
ndx++;
if (file.strFileName == ".")
continue;
LVITEM *pItem = new LVITEM;
pItem->iItem = 0;
file.strPower.Trim();
if (file.strPower.Left(1) == "d")
pItem->iImage = 0;
else
pItem->iImage = 1;
pItem->mask = CBEIF_IMAGE|CBEIF_TEXT|CBEIF_SELECTEDIMAGE;
pItem->iSubItem = 0;
str = file.strFileName;
strcpy(cStr,str);
pItem->pszText = cStr;
m_lstServerFile.InsertItem(pItem);
pItem->iItem = 0;
pItem->mask = CBEIF_TEXT;
pItem->iSubItem = 1;
str = file.strDate;
strcpy(cStr,str);
pItem->pszText = cStr;
m_lstServerFile.SetItem(pItem);
pItem->iItem = 0;
pItem->mask = CBEIF_TEXT;
pItem->iSubItem = 2;
nFileLenth = file.nSize;
str.Format ("%d",nFileLenth);
strcpy(cStr,str);
pItem->pszText = cStr;
m_lstServerFile.SetItem(pItem);
pItem->iItem = 0;
pItem->mask = CBEIF_TEXT;
pItem->iSubItem = 3;
str = file.strPower;
strcpy(cStr,str);
pItem->pszText = cStr;
m_lstServerFile.SetItem(pItem);
}
delete pItem;
}
BOOL CftpclientDlg::ChangeServerDir(LPSTR pszPath)
{
CString temp = CString(pszPath);
temp.Trim();
if( temp == "..")
{
if(!m_FtpClient.WriteStr("CDUP\n\r")) return FALSE;
if(!m_FtpClient.ReadStr()) return FALSE;
int i;
i = m_strServerFile.ReverseFind('\\');
m_strServerFile = m_strServerFile.Left(i);
}
else
{
CString cmd;
CString strPath = m_strServerFile;
strPath.Trim();
if (strPath.Right(1) != "\\" && strPath.GetLength() >=1)
strPath += "\\";
strPath += pszPath;
this->MessageBox(strPath);
cmd = "CWD" ;
cmd += pszPath;
cmd += "\n\r";
if(!m_FtpClient.WriteStr(cmd)) return FALSE;
if(!m_FtpClient.ReadStr()) return FALSE;
m_strServerFile = strPath;
}
return TRUE;
}
void CftpclientDlg::OnNMDblclkListServerfile(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: 在此添加控件通知处理程序代码
CString strFileName,strFileDir,strFileLenth,IsDir;
NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
CString str;
str.Format("%d",pLocInfo->item);
if(str=="-1")
return;
int nItem=atoi(str);
strFileName = m_lstServerFile.GetItemText(nItem,0);
strFileName.Trim();
strFileDir = m_strServerFile;
if (strFileDir.Right(1)!= "\\")
strFileDir += "\\";
strFileDir += strFileName;
//this->MessageBox(strFileDir);
IsDir = m_lstServerFile.GetItemText(nItem,3);
IsDir.Trim();
if(IsDir.Left(1)=="d")
{
char cPath[MAX_PATH];
strcpy(cPath,strFileName);
this->ChangeServerDir(cPath);
this->SetServerCmb(cPath,FALSE);
this->SetServerLst();
}
else
{
//下载文件
strFileLenth = m_lstServerFile.GetItemText(nItem,2);
int nFileLenth = atoi(strFileLenth);
m_proFileSpeed.SetRange(0,nFileLenth);
CString strLocalFile = m_strLocalFile;
if (strLocalFile.Right(1)!= "\\")
strLocalFile += "\\";
strLocalFile += strFileName;
if(!m_FtpClient.MoveFile(strFileName,strLocalFile,m_bIsPsv,TRUE))
{
this->SetMsg("下载不成功!");
return;
}
else
{
this->SetMsg("下载成功!");
}
}
*pResult = 0;
}
void CftpclientDlg::OnCbnSelchangeCmbServer()
{
// TODO: 在此添加控件通知处理程序代码
CString strPath;
char cPath[MAX_PATH];
m_cmbServerFile.GetWindowText(strPath);
strcpy(cPath,strPath);
this->ChangeServerDir(cPath);
this->SetServerLst();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -