首页 文章

请求用户名和密码后,我的FTP服务器自动终止与客户端的连接

提问于
浏览
0

所以,这是我的问题 . 顺便说一句,我正在使用Linux内置客户端 .

我在C中编写FTP服务器(TCP套接字),但在实现命令之前,客户端需要询问用户名和密码 . 如果它们是相同的,我必须授予用户访问权限 . 问题是,一旦我完成登录,我的服务器就会发送一个SYST命令并停止连接 . 在我的代码中,我分别调用220和331来检索用户和密码,以及230以授予访问权限 .

char login_user[BUFSIZ]; // Holds the username
char login_password[BUFSIZ]; //Holds the password
char buff1[BUFSIZ];
char buff2[BUFSIZ];
int x = 0, y = 0, compare = 0;
// Ask for the username   
send(sock, "220\r\n", 5, 0); 
x = read(sock, login_user, sizeof(login_user));
if(x < 0)
    perror("server: can't receive from client");
else
    login_user[x] = '\0';   
strncpy(buff1, login_user + 5, strlen(login_user)-7); //this copies only the username taking out surplus characters


// Ask for password   
send(sock, "331\r\n", 5, 0);
y = read(sock, login_password, sizeof(login_password));
if(y < 0)
    perror("server: can't receive from client");
else
    login_password[y] = '\0';
strncpy(buff2, login_password + 5, strlen(login_password)-7); //this copies only the password taking out surplus characters


// If username and password are the same, grant access, else exit connection
compare = strcmp(buff1, buff2);
printf("%s, %s, %d\n", buff1, buff2, compare);
if(compare == 0)
{
    send(sock, "230\r\n", 5, 0);
}
else
    send(sock, "421\r\n", 5, 0);

我想可能问题是我的vsftpd.conf文件,但是local_enable被激活了 . 欢迎任何建议:)

这就是客户端的样子:

user @ ubuntu:〜$ ftp

ftp>打开ubuntu 1111

连接到ubuntu .

220

名称(ubuntu:user):用户

331

密码:

230

421服务不可用,远程服务器已关闭连接

FTP>

1 回答

  • -1

    您和服务器之间的NAT防火墙显示症状 .

    问题就像ftp想要在新的,单独的TCP / IP连接中发送由命令产生的数据,并且无法通过防火墙,因为它需要从服务器转到您,并且您隐藏在防火墙后面 . 使用“pasv”命令更改为从您到服务器的数据连接的被动连接 .

    详情请见:Here

相关问题