Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c++

Status
Not open for further replies.

neeny

Programmer
Mar 16, 2002
3
US
How do you read in a file using c++ from the internet. Can you give an example.
 
I would suggest putting in a call to download it... like perhaps using a system(""...) call where the ""'s contain the ftp... And if you don't want it to take up harddrive space, you could always system("rm filename"); later to get rid of it... are you looking to write a browser of sorts? if so why not look at the source for Lynx or Links (yes they are seprate program both I believe are GNU GPL covered software).
 
Can you give an example of the code(function and main) to call a file into a program.
 
Well, I don't know exsactly what you are trying to do, and I'm only familiar with ftp on winDOZE machine, but in DJPPP (G++ for dos, I would actually do it something like this...)
In a batch.bat file:
ftp -s:file.txt server.com
In file.txt (exsactly what you'd type at the ftp prompt):
login <--login name
passwd <--pass word
lcd c:\pf
get mfile
bye
In CPP:
int main()
{
system(&quot;batch.bat&quot;);
ifstrea fin;
fin.open(&quot;mfile&quot;);
vector<char> buf;
while( !cin.eof() )
{
char ch;
cin>> noskipws >> ch;
buf.push_back(ch);
}
. . .


That of course is a cheap work around... and if I needed to get diffrent files from munlitple servers I'd use the file stream to write to file.txt and leave off the host in the batch file, or use the line in the batch as the thing between the quotes in the system. rember that system, noskipws, vector and filestrea all require included libraries.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top