gpt4 book ai didi

c++ - 使用 Winsock2 和 C++ 上传到 FTP 服务器

转载 作者:太空狗 更新时间:2023-10-29 23:19:41 25 4
gpt4 key购买 nike

我正在学习 winsock2,并用它制作了自己的聊天程序。现在我只是想知道是否有可能制作一个可以连接到 FTP 服务器并上传文件的程序。我在互联网上找到了很多“教程”,但他们似乎都使用自己的库,而不是 winsock2。

如何使用 winsock2 连接到 FTP?

最佳答案

阅读 FTP 协议(protocol)。连接到 FTP 服务器时的所有不同之处在于,有关于发送什么信号的规则,因为这些由协议(protocol)描述。

For information about the signals and structure of messages

登录 ftp 服务器的示例,假设 sock 是连接到 ftp 服务器的 ftp 端口 (21) 的套接字。

char loginMsg[] = "USER MyName\r\nPASS MyPass\r\n";
char responce[4] = {'\0'};
send(sock, loginMsg, strlen(loginMsg), 0);
recv(sock, responce, 3, 0);
if (strcmp(responce, "230") != 0)
// Could not log in to the ftp server

关于c++ - 使用 Winsock2 和 C++ 上传到 FTP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7420183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com