【发布时间】:2013-12-06 20:27:22
【问题描述】:
我正在尝试从 ftp 服务器手动接收文件。到目前为止,我可以连接到服务器并检查其220 响应,但随后我想发送用户名,wireshark 显示正在发送一些随机字节。
首先是我的代码:
struct request
{
int reply; /* TRUE = request reply from server */
int msgLen; /* length of message text */
char message[REQUEST_MSG_SIZE]; /* message buffer */
};
...
//ESTABLISH SOCKET CONNECTION
...
/* send request to server */
strcpy(myRequest.message,"ftp");
myRequest.msgLen = 3;
if (write (sFd, (char *) &myRequest, sizeof (myRequest)) == ERROR)
{
perror ("write");
close (sFd);
return ERROR;
}
if (read (sFd, replyBuf, REPLY_MSG_SIZE) < 0) {
perror ("read");
close (sFd);
return ERROR;
}
// CHECK if ser ver responded with code 220
if (strstr(replyBuf,"220")==NULL) {
perror ("Response220");
close (sFd);
return ERROR;
}
// send user name to server
strcpy(myRequest.message,"USER **");
myRequest.msgLen = 7;
if (write (sFd, (char *) &myRequest, sizeof (myRequest)) == ERROR)
{
perror ("write");
close (sFd);
return ERROR;
}
if (read (sFd, replyBuf, REPLY_MSG_SIZE) < 0) {
perror ("read");
close (sFd);
return ERROR;
}
printf ("MESSAGE FROM SERVER:\n%s\n", replyBuf);
但由于某种原因,我的发送字符串中似乎总是有一些随机字节: 首先,ftp 字符串如下所示:
36 1.767818000 3.94.213.214 3.94.213.53 FTP 70 Request: \356\356\356\356\000\000\000\003ftp\000"\032\244^
它可以处理,服务器回复:
38 1.777790000 3.94.213.53 3.94.213.214 FTP 74 Response: 220 (vsFTPd 3.0.2)
但是 USER 字符串看起来像这样:
40 1.781575000 3.94.213.214 3.94.213.53 FTP 70 Request: \356\356\356\356\000\000\000\aUSER **\000
不出所料,它无能为力。在此之后,我希望服务器会要求我输入密码。
客户端运行在 VxWorks 机器上,服务器是 Linux 上的 vsFTP
【问题讨论】:
标签: c sockets networking ftp vxworks