char RemoteFileName[60]; TCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1; if(GetComputerName(chrComputerName,&dwBufferSize)) { // We got the name, set the return value. strcpy(RemoteFileName,chrComputerName); you may need to #include
wootski
Posts
-
values of language,computer name and user name -
Winwock Get Request HelpHello, I was reading one of the tutorials on your site and thought I would try code something that could download files off the internet. However, when I try to download large files or ones that use weird characters the files become corrupt and do not work. This is the case for .rar,.zip and many other formats. Further, I am unable to get information from .asp sites at all!? Any help would be greatly appreciated.
g++ ws.cpp -lws2_32
Note: Include files altered to work with this forum, missing "<"#include winsock2.h> #include ws2tcpip.h> #include stdio.h> #include iostream> #include fstream> using namespace std; int main() { char servername[40] = "members.myserver.com"; char filepath[40] = "/username/file.rar"; char filename[20] = "downloadedfile.rar"; char buff[512]; struct hostent *hp; unsigned int addr; struct sockaddr_in server; int y; WSAData wsaData; // Initialize Winsock int iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != 0) { printf("WSAStartup failed: %d\n", iResult); return 1; } SOCKET conn; conn=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(conn==INVALID_SOCKET) return 0; if(inet_addr(servername)==INADDR_NONE) { hp=gethostbyname(servername); } else { addr=inet_addr(servername); hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET); } if(hp==NULL) { closesocket(conn); return 0; } server.sin_addr.s_addr=*((unsigned long*)hp->h_addr); server.sin_family=AF_INET; server.sin_port=htons(80); if(connect(conn,(struct sockaddr*)&server,sizeof(server))) { closesocket(conn); return 0; } sprintf(buff,"GET %s\r\n\r\n",filepath); send(conn,buff,strlen(buff),0); ofstream file; file.open(filename); while(y=recv(conn,buff,512,0)) { file << buff; //gets some slight errors } file.close(); closesocket(conn); WSACleanup(); return 0; }
Thanks! =D