|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
C language Ftp sending in windows
I want to upload some text file through ftp . how can I done this ???
I'm now using Borland Turbo C and it's have many preprocessor that i don't know what meaning of using it -_-" (My OS = window) I'm just a newbie T^T pls help me out of this problem ToT sorry I'm very poor in english ^^" |
|
#2
|
||||
|
||||
|
This might help:
http://www.cpp-home.com/tutorial.php?256_1 edit: Looking back at the link, nm it, it sucks, I don't think it's what your looking for. Last edited by movEAX_444 : August 31st, 2003 at 01:25 PM. |
|
#3
|
||||
|
||||
|
you want to write an ftp client? you should probably read the ftp protocol so you understand exactly how the data transfers work. just connecting to the server and sending commands is easy, but transferring data is a bit more complex. you'll need to open up an additional port(20 i believe) to do the transfer. here is the ftp rfc, ftp://ftp.rfc-editor.org/in-notes/rfc959.txt
and here is some sample code of something i was workin on to get you started. this just connects and sees if the ftp is writeable, but it should give a rough idea of what to do. Code:
#include "my_sock.h"
#define N_COMMANDS 6 //number of commands
#define PORT 21 //ermduh
#define SALEN 16 //sockaddr_in size
#define TIMEOUT 10 //listening TO
char *command[] = //these are the commands we send to ftp server
{
"USER anonymous\r\n",
"PASS asdf@aol.com\r\n",
"SYST\r\n",
"TYPE I\r\n",
"PASV\r\n",
"STOR fale\r\n"
};
int
main(int argc, char **argv)
{
if(argc != 2) printf("Usage: %s <ip>\n", argv[0]), exit(1);
int sock = 0, nread = 0, x = 0, in_sz[N_COMMANDS];
char buf[ETH_FRAME_LEN];
struct sockaddr_in sa;
struct timeval ts;
bzero(&sa, SALEN), bzero(buf, ETH_FRAME_LEN), bzero(&ts, sizeof(struct timeval));
//setup address structure
sa.sin_family = AF_INET;
sa.sin_port = htons(PORT);
sa.sin_addr.s_addr = inet_addr(argv[1]);
ts.tv_sec = TIMEOUT; //socket timeout
//get the size of each command w/o NULL terminator and reset x
for(x; x < N_COMMANDS; x++)
in_sz[x] = strlen(command[x]);
x = 0;
printf(".-~'`ftp_find`'~-.\n"); //hi
//create socket
if( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
perror("sock"), exit(0);
//set timeout option
if( (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &ts, sizeof(ts))) != 0)
perror("setsockopt"), exit(0);
//open named pipe for reading and wait for input from other process
//only wait for 1 hour at max then save and shutdown
//connect to server
if( (connect(sock, (struct sockaddr *)&sa, SALEN)) < 0)
perror("con"), exit(0);
else
printf("connected to %s...\n", argv[1]);
while(x <= N_COMMANDS) //loop one extra time to read last reply
{
sleep(1); //let the server breathe
if(x < N_COMMANDS) //skip sending in final loop
{
if( (nread = write(sock, command[x], in_sz[x])) < 1)
perror("write"), exit(0);
printf("sending command:%s", command[x]);
}
//a timeout indicates success if all commands have been sent,,,, USUALLY
if( (nread = recv(sock, buf, ETH_FRAME_LEN, 0)) < 1)
{
if(errno == EAGAIN) //usually on success we timeout waiting for response
goto end;
else
perror("read"), exit(0);
}
//if a command isnt accepted/fails then the response code starts with a 4 or 5 like HTTP
if( (buf[0] == '4') || (buf[0] == '5'))
printf("\ncommand rejected, moving on to next target\n"), exit(0);
else
printf("...\n");
x++;
}
//status and cleanup
end:
if(x == N_COMMANDS)
printf("Success, logging %s as pub\n", argv[1]);
else
printf("Failure\n");
exit(1);
}
|
|
#4
|
|||
|
|||
|
I personally use Wininet. Comes with Windows API SDK, and the DLL comes with IE. Most functions require IE 3 or IE 5, but if you "statically" link it and distribute the DLL, it doesn't need that.
![]() Function list is here: http://msdn.microsoft.com/library/d...t_functions.asp Hope this helps! Regards, Someonewhoi |
|
#5
|
||||
|
||||
|
My suggestion is you create a simple FTP batch file and call it from the C system() command and save yourself a lot of trouble.
__________________
Left DevShed May 28, 2005. Reason: Unresponsive administrators. Free code: http://sol-biotech.com/code/. Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html. Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html. It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it. --Me, I just made it up The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man. --George Bernard Shaw |
|
#6
|
|||
|
|||
|
Thx a lot everyone ^^
What's that long script O_O""""""""""""" arrrrrrrrrrrggghhhh I'm going crazy T_T~ |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > C language Ftp sending in windows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|