【发布时间】:2015-02-08 05:32:12
【问题描述】:
我正在尝试使用以下代码实现一个 ftp 服务器:
64 if (command_sock == -1){
65 printf("error accepting socket connection: errno = %d\n", errno);}
66 else{printf("connection accepted\n");}
67
68 send(command_sock, "220 FTP Server ready\n", 25, 0);
69
70 int image_mode = 0; //not set to "I"
71 int file_str = 1; //file mode by default
72
73 while(1){
74 recv(command_sock, buffer, 512, 0);
75 sscanf(buffer, "%s %[^\n]s", command, arg);
76 printf("command = \"%s\"\n", command);
77 printf("arg = %s\n", arg);
78
79
80 if(strcmp(command, "USER") == 0){
81 send(command_sock, "230 user logged in\n", 35, 0);
82 }
83 else if(strcmp(command, "QUIT") == 0){
84
85 close(command_sock);
86 close(send_1);
87 goto listen;
88
89
90 }
但是当我尝试登录时它失败了,因为第 81 行确实发送了“%s 230 用户登录\n”。
root@nodeforcetwo:/home/rustyventure/opsys/mac_5# ftp
ftp> open 127.0.0.1 3500
Connected to 127.0.0.1.
220 FTP Server ready
Name (127.0.0.1:rustyventure): rusty
%s 230 user logged in
Login Failed
谁能明白为什么,我在这里不知所措。
谢谢
【问题讨论】: