建立單文檔時:
一步一步來的時候,需要選中採用window socket選項
建立FTP服務器:
HOME FTP SERVER服務器建立的
登錄:
{
// TODO: 在此添加控件通知處理程序代碼
try
{
// Request a connection to ftp.microsoft.com. Default
// parameters mean that we'll try with username = ANONYMOUS`
// and password set to the machine name @ domain name
UpdateData();
if (m_csAddress.IsEmpty())
{
MessageBox("服務器地址不能爲空");
GetDlgItem(IDC_EDIT_ADDRESS)->SetFocus();
return;
}
if (m_csUserName.IsEmpty())
{
MessageBox("用戶名不能爲空");
GetDlgItem(IDC_EDIT_USER_NAME)->SetFocus();
return;
}
// CString strTemp;
// strTemp.Format("%s,%s,%s",m_csAddress,m_csUserName,m_csPwd);
// MessageBox(strTemp);
//正式建立連接
pConnect = sess.GetFtpConnection(m_csAddress,m_csUserName,m_csPwd);
//pConnect = sess.GetFtpConnection("localhost","wang","851188");
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
CString errstr;
errstr.Format("%s",sz);
//printf("ERROR! %s\n", sz);
MessageBox(errstr);
pEx->Delete();
}
if (pConnect!=NULL)
{
GetDlgItem(IDC_STATIC_TIP_INFO)->SetWindowText("登錄成功!");
GetDlgItem(IDC_EDIT_USER_NAME)->SetWindowText("");
GetDlgItem(IDC_EDIT_PASSWORD)->SetWindowText("");
}
else
{
GetDlgItem(IDC_STATIC_TIP_INFO)->SetWindowText("沒有登錄成功!");
}
}
上傳文件 :
void CFtpDlg::OnBnClickedButtonUpload()
{
BOOL isUpload=FALSE;
UpdateData();
CString str;
//截取文件名
int i=m_filePath.ReverseFind('\\');
str+=m_filePath.Mid(i+1);
if (pConnect!=NULL)
{
isUpload=pConnect->PutFile(m_filePath,str);
//m_mfcEditBrowseCtrl.GetStyle();
}
if (isUpload)
{
MessageBox("上傳文件成功");
}
else
{
MessageBox("上傳文件失敗");
}
}