[問題] 請問用C寫FTP的login問題
小弟目前再寫一個console介面的FTP Client端程式
有study了winsocket和RFC的一些東西
目前做出來的情況是感覺好像連上,但不知怎麼login
不知username,password的設定要怎麼寫?
開發的平台是用VC++ 6
目前的code如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#ifdef _WIN32
#include <winsock.h>
#pragma comment(lib,"wsock32.lib")
#else
#define SOCKET int
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#define SERVER_IP "163.28.80.21"
#define SERVER_PORT 21
int main(void)
{
#ifdef _WIN32
/*** Initial WSA ***/
int WSAState;
WSADATA wsaData;
WSAState = WSAStartup(0x101, &wsaData);
if(WSAState){
printf("Initial WSA Error!, error code:%d\n", WSAState);
exit(EXIT_FAILURE);
}
#endif
/*** Create a Socket ***/
SOCKET ConnectSocket;
ConnectSocket = socket(PF_INET,SOCK_STREAM,0);
if(ConnectSocket == INVALID_SOCKET){
printf("Error occurred in socket()");
#ifdef _WIN32
WSACleanup();
#endif
exit(EXIT_FAILURE);
}
/*** Inital host address and port ***/
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(SERVER_IP);
server.sin_port = htons(SERVER_PORT);
/*** Connect to Server ***/
if(connect(ConnectSocket,(struct sockaddr*)&server,sizeof(server)) ==
SOCKET_ERROR){
printf("Error occurred in connect\n");
#ifdef _WIN32
WSACleanup();
#endif
exit(EXIT_FAILURE);
}else printf(" Connecting to Server...!\n");
/*** close socket ***/
#ifdef _WIN32
closesocket(ConnectSocket);
WSACleanup();
#else
close(ConnectSocket);
#endif
return 0;
}
請各位高手大大能多指點指點,拜託拜託!!!
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.137.183.152
→
09/05 13:43, , 1F
09/05 13:43, 1F
→
09/05 13:43, , 2F
09/05 13:43, 2F
→
09/05 13:44, , 3F
09/05 13:44, 3F
推
09/05 15:17, , 4F
09/05 15:17, 4F
推
09/05 16:01, , 5F
09/05 16:01, 5F
→
09/05 16:01, , 6F
09/05 16:01, 6F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章