File copy over HTTP

P

Pramod

Hello All,

I want to copy few files from a server using HTTP URL in C++.

for ex. I have a file located at: http://localhost/myFolder/myFile.txt
which needs to copied at a specific folder on my client machine. The C+
+ program would be running on client machine and has access to this
URL file.

Any pointers in this regards are appreciated.

Thanks,
PSI
 
S

Sjouke Burry

Pramod said:
Hello All,

I want to copy few files from a server using HTTP URL in C++.

for ex. I have a file located at: http://localhost/myFolder/myFile.txt
which needs to copied at a specific folder on my client machine. The C+
+ program would be running on client machine and has access to this
URL file.

Any pointers in this regards are appreciated.

Thanks,
PSI
Get hold of "wget.exe" a gnu utility.
then in your program do:
system("wget http://localhost/myFolder/myFile.txt");
which puts it in your current working directory.
 
S

Sousuke

Get hold of "wget.exe" a gnu utility.
then in your program do:
        system("wgethttp://localhost/myFolder/myFile.txt");
which puts it in your current working directory.

IMO, using the system function for things like this is rather hackish.
Things like this should be handled in the program or by some library
or API.

If the OP is indeed on Windows, then there's a native API for that:
WinHTTP:

http://msdn.microsoft.com/en-us/library/aa382925(VS.85).aspx
 
J

Jorgen Grahn

On Mar 25, 6:52 am, Sjouke Burry <[email protected]>
wrote:

IMO, using the system function for things like this is rather hackish.
Things like this should be handled in the program or by some library
or API.

The exact code above is hackish, yes: for example he has no direct
control over where the file ends up (if myFile.txt already exists wget
by default saves the data as myFile.txt.1) and it doesn't check if it
succeeded. Might even be a security hole in some cases.

But in many other cases reinventing the wheel or even using a library
would look odd. For example it's fairly normal for Unix programs to
read gzipped files by popen()ing gzip -cd.

/Jorgen
 
S

Sjouke Burry

Jorgen said:
The exact code above is hackish, yes: for example he has no direct
control over where the file ends up (if myFile.txt already exists wget
by default saves the data as myFile.txt.1) and it doesn't check if it
succeeded. Might even be a security hole in some cases.

But in many other cases reinventing the wheel or even using a library
would look odd. For example it's fairly normal for Unix programs to
read gzipped files by popen()ing gzip -cd.

/Jorgen
??? You dont have control over your current working directory??
Strange...
 
J

Jorgen Grahn

??? You dont have control over your current working directory??
Strange...

I assume you are talking about the myFile.txt versus myFile.txt.1
issue I mentioned above?

No, my /program/ sure doesn't have control over that. And I don't feel
like explaining things like "the program will silently fail if you
have a file named so-and-so in your current directory" in the user
documentation.

So it's not strange to me. It's part of building robust, secure and
usable programs.

(It's not an issue if I'm the only user and will only use the program
for a few days, but that's not normally the case for C++ programs.)

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,174
Latest member
BlissKetoACV
Top