简体   繁体   中英

Upload to a FTP server using Winsock2 and C++

I'm learning winsock2, and I made my own chat programs with it. Now I just wonder if it is possible to make a program that can connect to a FTP server and upload a file. I have found many "tutorials" on the Internet, but they all seem to use their own library, and not winsock2.

How do I connect to FTP with winsock2?

Read up on the FTP protocol. All that is different when connecting to an FTP server is that there are rules about what signals to send as theses are described by the protocol.

For information about the signals and structure of messages

An example of logging into an ftp server assuming that sock is a socket connected to the ftp port (21) of the ftp server.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM