一、用到的CInternetSession、CFtpConnection类的接口
二、编码实现
/*
参数说明:
remotefile 要下载的ftp目录或文件,如"/杭州/滨江/五水共治.rar"
localpath 保存到本地的目录,如"D:\\Download"
isDir 指明要下载的是文件还是文件夹
ftpaddr ftp服务器地址
username 登陆ftp服务器的用户名
ftpPass 登陆f密码
*/
BOOL DownloadFromFTP(CString remotepath,CString localpath,BOOL isDir,CString ftpaddr,CString username,CString password,int port)
{
int index = remotepath.ReverseFind('/');
if (index == -1)
{
return FALSE;
}
CString remotefile = remotepath.Mid(index+1,remotepath.GetLength());
CInternetSession sess(_T("Download Files Session"));
CFtpConnection* pFtpCon = NULL;
try
{
pFtpCon = sess.GetFtpConnection(ftpaddr,username,password,port);
if (pFtpCon == NULL) //如果连接失败
{
return F