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;