October 8th, 2003, 05:40 AM
manipulating files stored on a website
I'm using borland C++ 4.5
I need a program to run on my pc, but it needs to be able to read and write files that are stored on my website (on a server, not my own pc).
I would like to be able to do this directly, as well as using the C program to run cgi scripts on my site and pass variables back and forth.
Is it possible to do this with the C language I'm using? If it is how do I make the connections?
October 8th, 2003, 05:46 AM
It is not as simple as opening a file, unless, of course, you obtain a library that allows that. You will have to open a socket to the server program (keep in mind that ANYONE can open the same socket, so you have a massive security hole unless you want to learn about cryptology and authentication), make a request to the server via the socket (since it is just a bunch of bits going back and forth, you get to invent your own protocol), then return the bits from the file on the server. It is not terribly complicated, but you do need to understand sockets pretty well as well as TCP/IP. There are programming APIs you can use, such as NFS, Netbui, etc. All with varying degrees of (or lack of) security. When you attach a server to a port on a computer connected to the Internet, you are really letting your pants down. Using CGI to accomplish the same thing does not provide any additonal security, just an additional layer of abstraction.
Have you considered FTP? Or its secure cousin SFTP?
October 8th, 2003, 06:04 AM
ftp could work but I have no clue how to connect to ftp from C either. and I would still need to be able to run cgi scripts on the server from the program. I'm thinking passing arguments wouldn't be necessary if I can read and write the files in the C program. I'm wondering if I can call internet explorer from the C program using the address to the cgi as an arguement. if I can do this then that only leaves the matter of transfering files, ftp would work for that if you can tell me how to connect to ftp in C
October 8th, 2003, 06:12 AM
I have solved the 'ftp problem' by calling batch files from my programs. As for doing CGI, you can execute CGI scripts just like downloading a web page in C code, but of course, you need to know socket programming. Windows has a bunch of APIs that greatly simplify the need to know low-level detail. Look up the afxinet header file and the classes CInternetSession, CHttpConnection and CHttpFile. I like to do things the hard way, but I am not prepared to give out my buggy code that has cost me tens of hours of headaches so easily.