1

已编辑

我正在制作一个 C++ 程序,用于连接到我学校的 FTP 服务器并允许我从我的帐户中获取文件。没什么复杂的,但我一直遇到 530 返回码。我首先在端口 21(FTP 命令端口)上建立套接字并发送,USER xxxxx然后我得到一个 220 代码响应,说我已连接到 111.111.111,接下来我将发送用户命令PASS xxxxx,但密码未被接受并且我得到一个 331 代码

这是运行以下代码的终端:

>./FTP
FTP: USER xxxxx
FTP: 220 csci2.stcloudstate.edu FTP server ready.
FTP: PASS xxxxx
FTP: 331 Password required for xxxxx.
 ready.
FTP: PASS xxxxx
FTP: 530 Please login with USER and PASS.
ready.
>

我在想我的命令格式不正确,所以下面是代码如果有人看到我的用户/密码输入出错的地方。

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <iostream>
using namespace std;

int main(void)
{
        //variables
    struct sockaddr_in stSockAddr;
    int Res;
    char buff[60];
    char UserFeed[30];
    int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
    string FTPread;
    string FtpCommand;
        ...
    memset(&stSockAddr, 0, sizeof(stSockAddr)); 
    stSockAddr.sin_family = AF_INET;
    stSockAddr.sin_port = htons(21);
        ...

    //Enter USER xxxxxx
    cout<<"FTP: ";
    fgets(UserFeed,30,stdin);
    write(SocketFD, UserFeed, strnln(UserFeed));
    recv(SocketFD,buff,sizeof(buff),0);
    cout<<"FTP: "<<buff;

    //Enter PASS xxxxxxxx
    cout<<"FTP: ";
    fgets(UserFeed,30,stdin);
    write(SocketFD, UserFeed, strnln(UserFeed));
    recv(SocketFD,buff,sizeof(buff),0);
    cout<<"FTP: "<<buff;
        ...
}

*注意:这是使用 berkeley 套接字,FTP 将是被动模式(因此还没有数据连接),这是从与 FTP 服务器位于同一网络上的 solaris 系统编码/编译/运行的。

4

0 回答 0