我尽量让简单的FTP客户端来获取有关BSD套接字文件列表。这里是:Linux上的“500 '' FTP客户端:命令不被理解。 “
connectTo(int client_socket,
struct sockaddr_in* addr,
char* ipv4Address,
char* user,
char* password,
char* response) // buffer wchich store responses
{
client_socket = socket(AF_INET, SOCK_STREAM, 0);
if(socket < 0)
{
printf("Can not create socket");
return 2;
}
addr->sin_family = AF_INET; // address family - internet socket
addr->sin_port = htons(PORT_NUMBER);
addr->sin_addr.s_addr = inet_addr(ipv4Address);
if(connect(client_socket,(struct sockaddr*)addr,sizeof(*addr)) < 0)
{
printf("Can not connect!\n");
return 3;
}
int size_read = recv(client_socket, response, BUF_SIZE, 0);
printf("size_read = %d\n",size_read);
response[size_read] = '\0'; // for not printing rubbish
printf("%s\n",response);
printf("sending username\n");
char *username = strdup("USER trenkinan\r\n");
send(client_socket,username,strlen(username)+1,0);
size_read = recv(client_socket, response, BUF_SIZE, 0);
// printf("size_read = %d\n",size_read);
response[size_read] = '\0'; // for not printing rubbish
printf("%s",response);
if(strstr(response,"331"))
{
//printf("sending password\n");
char *passwd = strdup("PASS test\r\n");
// printf("passwd string: %s",passwd);
int sent = send(client_socket,passwd,strlen(passwd)+1,0);
size_read = recv(client_socket, response, BUF_SIZE, 0);
response[size_read] = '\0'; // for not printing rubbish
printf("%s",response);
//printf("sent bytes: %d\n", sent);
}
return 0;
}
我在我的工作站上从debian仓库(ftpd)使用ftp服务器。我尝试执行此代码,当我发送密码服务器答案,500':命令不明白。 我使用Wireshark来看看会发生什么,以及我的程序包都看起来不错,我用ftp命令(轻量级FTP客户端linux上)连接和它的作品,但是从客户端软件包看起来一样从我自己的客户端。有任何想法吗?