📄 httpthreadget.cpp
字号:
// HttpThreadGet.cpp : Defines the class behaviors for the application.
#include "stdafx.h"
#include "HttpThreadGet.h"
#include "HttpGet.h"
#include "FtpGet.h"
#include "Dealsocket.h"
#include "myfile.h"
BEGIN_MESSAGE_MAP(CHttpThreadGetApp, CWinApp)
//{{AFX_MSG_MAP(CHttpThreadGetApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHttpThreadGetApp construction
CHttpThreadGetApp::CHttpThreadGetApp()
{
}
CHttpThreadGetApp theApp;
// 假设FTP代理服务器为192.168.1.30, 你要的ftp主机为www.ChengMengEn.org;
// 用户帐号为vcd, 口令为godsword.
// 用FTP代理服务器则相应改为-FTP主机:192.168.1.30;
// 用户帐号为 vcd@www.ChengMengEn.org, 口令为godsword.
void MyFtp(BOOL bProxy,BOOL bList,BOOL bPasv)
{
CFtpGet a;
CString host,userName,pass;
int port;
if(bProxy){
host="192.168.1.30";
port=2121;
userName="vcd@www.ChengMengEn.org";
pass="godsword";
}
else{
host="www.ChengMengEn.org";
port=21;
userName="vcd";
pass="godsword";
}
if(bList){
SOCKET hCtrlSock=a.ConnectFtp(host,port,userName,pass);
a.DirList(hCtrlSock,bPasv);
}
else{
CString strFtpFileName="church/church_01.mpg";
CString strWriteFileName;
strWriteFileName.Format
("c:\\%s",myfile.GetShortFileName(strFtpFileName));
a.FtpDownLoad(host,port,
userName ,pass, strFtpFileName,strWriteFileName,3,bPasv);
}
}
//---------------------------------------------------------------------------
// 从URL中提取主机名称、下载文件路径和文件名.
void ParseURL(CString URL,CString &host,CString &path,CString &filename)
{
URL.TrimLeft();
URL.TrimRight();
CString str=URL;
CString strFind=_T("http://");
int n=str.Find(strFind);
if(n!=-1){
str.Delete(0, n+strFind.GetLength());
}
n=str.Find('/');
host = str.Left(n);
n=URL.ReverseFind('/');
path = URL.Left(n+1);
filename = URL.Right(URL.GetLength()-n-1);
}
void MyHttp(BOOL bProxy)
{
CHttpGet b;
CString strHostAddr;
CString strHttpAddr;
CString strHttpFilename;
CString strWriteFileName;
CString lpszURL="http://www.netants.com/download/netants_gb2312.zip";
ParseURL(lpszURL,strHostAddr,strHttpAddr,strHttpFilename);
strWriteFileName.Format("c:\\%s",strHttpFilename);
if(bProxy){
CString strProxyAddr="192.168.1.30";
int nProxyPort=81;
b.HttpDownLoadProxy(strProxyAddr,nProxyPort,
strHostAddr,strHttpAddr,strHttpFilename,strWriteFileName,2);
}
else{
b.HttpDownLoadNonProxy(strHostAddr,
strHttpAddr,strHttpFilename,strWriteFileName,2);
}
}
BOOL CHttpThreadGetApp::InitInstance()
{
// MyHttp(false);
MyFtp(false,true,true);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -