【问题标题】:manully establish connection to ftp server using sockets使用套接字手动建立到 ftp 服务器的连接
【发布时间】: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


    【解决方案1】:

    你为什么要通过套接字发送结构,你只需要发送数据。此外,您不能通过同一连接发送数据.....一旦您与 ftpd 建立的第一个连接是命令连接,当您发送数据时,另一个连接将打开。我想您需要先查看 FTP RFC 959,然后再继续。

    【讨论】:

      猜你喜欢
      • 2018-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-27
      • 2012-05-16
      • 2018-02-18
      • 1970-01-01
      相关资源
      最近更新 更多