[問題] 請問用C寫FTP的login問題

看板C_and_CPP (C/C++)作者 (渴望)時間15年前 (2010/09/05 12:54), 編輯推噓2(204)
留言6則, 3人參與, 最新討論串1/1
小弟目前再寫一個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
你可以先拿個FTP Client執行,用Wireshark觀察它的動作
09/05 13:43, 1F

09/05 13:43, , 2F
譬如登入時送出了哪些封包 你就可以模仿去做
09/05 13:43, 2F

09/05 13:44, , 3F
也建議去找一下FTP這個協定的相關資料
09/05 13:44, 3F

09/05 15:17, , 4F
用telnet去連一下就知道了
09/05 15:17, 4F

09/05 16:01, , 5F
ftp 要2 個connection (data/command), 你要不要先
09/05 16:01, 5F

09/05 16:01, , 6F
寫個ntp 就好了...
09/05 16:01, 6F
文章代碼(AID): #1CWo9lTw (C_and_CPP)
文章代碼(AID): #1CWo9lTw (C_and_CPP)