Click here to Skip to main content
15,891,529 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: About information of the file Pin
ritz123418-Apr-08 19:56
ritz123418-Apr-08 19:56 
GeneralRe: About information of the file Pin
Le@rner18-Apr-08 20:18
Le@rner18-Apr-08 20:18 
GeneralRe: About information of the file Pin
ritz123418-Apr-08 20:45
ritz123418-Apr-08 20:45 
GeneralRe: About information of the file Pin
Le@rner18-Apr-08 21:07
Le@rner18-Apr-08 21:07 
GeneralRe: About information of the file Pin
ritz123418-Apr-08 21:13
ritz123418-Apr-08 21:13 
GeneralRe: About information of the file Pin
ritz123418-Apr-08 19:52
ritz123418-Apr-08 19:52 
QuestionRe: About information of the file Pin
David Crow19-Apr-08 3:35
David Crow19-Apr-08 3:35 
GeneralWinwock Get Request Help Pin
wootski18-Apr-08 18:54
wootski18-Apr-08 18:54 
Hello, 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 "<"
<br />
#include winsock2.h><br />
#include ws2tcpip.h><br />
#include stdio.h><br />
#include iostream><br />
#include fstream><br />
<br />
using namespace std;<br />
<br />
<br />
int main() {<br />
<br />
char servername[40] = "members.myserver.com";<br />
char filepath[40] = "/username/file.rar";<br />
char filename[20] = "downloadedfile.rar";<br />
char buff[512];<br />
struct hostent *hp;<br />
unsigned int addr;<br />
struct sockaddr_in server;<br />
int y;<br />
<br />
<br />
WSAData wsaData;<br />
// Initialize Winsock<br />
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);<br />
if (iResult != 0) {<br />
    printf("WSAStartup failed: %d\n", iResult);<br />
    return 1;<br />
}<br />
<br />
<br />
<br />
 SOCKET conn;<br />
conn=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);<br />
if(conn==INVALID_SOCKET)<br />
    return 0;<br />
<br />
<br />
if(inet_addr(servername)==INADDR_NONE)<br />
{<br />
    hp=gethostbyname(servername);<br />
}<br />
else<br />
{<br />
    addr=inet_addr(servername);<br />
    hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);<br />
}<br />
if(hp==NULL)<br />
{<br />
    closesocket(conn);<br />
    return 0;<br />
}<br />
<br />
<br />
server.sin_addr.s_addr=*((unsigned long*)hp->h_addr);<br />
server.sin_family=AF_INET;<br />
server.sin_port=htons(80);<br />
if(connect(conn,(struct sockaddr*)&server,sizeof(server)))<br />
{<br />
    closesocket(conn);<br />
    return 0;<br />
}<br />
<br />
<br />
sprintf(buff,"GET %s\r\n\r\n",filepath);<br />
send(conn,buff,strlen(buff),0);<br />
<br />
<br />
ofstream file;<br />
file.open(filename);<br />
<br />
while(y=recv(conn,buff,512,0))<br />
{<br />
	file << buff; //gets some slight errors<br />
}<br />
<br />
<br />
file.close();<br />
closesocket(conn);<br />
<br />
<br />
WSACleanup();<br />
<br />
  return 0;<br />
}<br />

Thanks! =D
Generalvalues of language,computer name and user name Pin
neha.agarwal2718-Apr-08 18:44
neha.agarwal2718-Apr-08 18:44 
GeneralRe: values of language,computer name and user name Pin
wootski18-Apr-08 18:57
wootski18-Apr-08 18:57 
GeneralRe: values of language,computer name and user name Pin
Le@rner18-Apr-08 19:05
Le@rner18-Apr-08 19:05 
GeneralRe: values of language,computer name and user name Pin
Hamid_RT18-Apr-08 20:34
Hamid_RT18-Apr-08 20:34 
QuestionVisual C++ 6.0 How do I put copyright symbol in Help About box Pin
Kwanalouie18-Apr-08 12:01
Kwanalouie18-Apr-08 12:01 
GeneralRe: Visual C++ 6.0 How do I put copyright symbol in Help About box Pin
Michael Schubert18-Apr-08 12:47
Michael Schubert18-Apr-08 12:47 
GeneralRe: Visual C++ 6.0 How do I put copyright symbol in Help About box Pin
chandu00418-Apr-08 21:48
chandu00418-Apr-08 21:48 
GeneralRe: Visual C++ 6.0 How do I put copyright symbol in Help About box Pin
Joe Woodbury20-Apr-08 17:37
professionalJoe Woodbury20-Apr-08 17:37 
QuestionData members Pin
jpyp18-Apr-08 11:53
jpyp18-Apr-08 11:53 
GeneralRe: Data members Pin
Gary R. Wheeler19-Apr-08 1:44
Gary R. Wheeler19-Apr-08 1:44 
GeneralMFC-- coding behind a button Pin
komalwaseem18-Apr-08 9:38
komalwaseem18-Apr-08 9:38 
GeneralRe: MFC-- coding behind a button Pin
Michael Schubert18-Apr-08 12:20
Michael Schubert18-Apr-08 12:20 
GeneralRe: MFC-- coding behind a button Pin
Hamid_RT18-Apr-08 18:15
Hamid_RT18-Apr-08 18:15 
QuestionRe: MFC-- coding behind a button Pin
David Crow19-Apr-08 3:39
David Crow19-Apr-08 3:39 
GeneralHWND nach LPCWSTR casten Pin
Rahvin18-Apr-08 9:11
Rahvin18-Apr-08 9:11 
GeneralRe: HWND nach LPCWSTR casten Pin
CPallini18-Apr-08 9:21
mveCPallini18-Apr-08 9:21 
GeneralRe: HWND nach LPCWSTR casten Pin
Garth J Lancaster18-Apr-08 13:36
professionalGarth J Lancaster18-Apr-08 13:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.