Java、Python 和其他类似的东西毁了我。我正在尝试通过响应服务器代码来自动化 FTP 客户端:
例如:
// I know this is ugly, please bear with me
char username[25];
strcat(username, USER); //"USER "
strcat(username, usr); // "foo"
strcat(username, "\n"); // = "USER foo\n"
char password[25];
strcat(password, PASS); //"PASS "
strcat(password, pswd); //"bar"
strcat(password, "\n"); // = "PASS bar\n"
//read/write loop
while (1) {
char* responsePtr;
serverCode = readSocket(sockfd, mybuffer);
if (serverCode == 221)
break;
if (serverCode == 220)
responsePtr = &username;
if (serverCode == 331)
responsePtr = &password;
writeSocket(sockfd, responsePtr);
}
当我尝试这个时,它适用于 USER,但我得到一些错误的 PASS 文本:
C->S: USER anonymous
S->C: 331 Please specify the password.
C->S: (??_?PASS random
谁能比我更聪明、更有经验给我一些 C 字符串指针?显然这不适合我。