tiaolongmen

ftp上传文件

CInternetSession* pInetSession;
CFtpConnection* pFtpConnection;
 
CString username; //用户名
CString password; //密码
CString strHost; //服务器ip
CString strPort; //端口号
CString strServerPath;//服务器端存储文件路径
CString strRemote; //服务器端文件名称
CString strLocal; //本地文件名(包括路径)
 
int iPort = atoi(m_strPort);
// 连接 FTP server
pInetSession=new CInternetSession("FTP",1,PRE_CONFIG_INTERNET_ACCESS);
try
{
  pFtpConnection=pInetSession->GetFtpConnection(strHost,username,password,iPort,TRUE);
}
catch(CInternetException *pEx)
{
  pEx->Delete();
  pFtpConnection=NULL;//连接ftp服务器失败 
  return false;
}
if(pFtpConnection->SetCurrentDirectory(strServerPath))
{
  if(pFtpConnection->PutFile(strLocal,strRemote))
  {
      //上传文件完成      
  }
  else
  {
    int nLastError = GetLastError();
    CHAR szError[256]={0};
    DWORD dwErrorSize = 256;
    CString m_strTmperror = szError;
    //上传文件失败
  }
}
 
pFtpConnection->Close();
return TRUE;
posted on 2012-09-20 10:37  一缕阳光 一道晚霞  阅读(174)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章: