Sobes.tech
Junior — Middle

Can you explain what the FTP protocol is and what it is used for?

sobes.tech AI

Answer from AI

FTP (File Transfer Protocol) is a network protocol for transferring files between a client and a server over a TCP/IP network. It is used for uploading and downloading files, as well as managing files on a remote server.

Main features:

  • Operates on a client-server model
  • Uses two channels: control (commands) and data (file transfer)
  • Supports user authentication

Example of use: uploading a website to hosting via FTP client.

Example of a C++ command using the libcurl library to download a file via FTP:

#include <curl/curl.h>

int main() {
    CURL *curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt");
        curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
        curl_easy_setopt(curl, CURLOPT_PASSWORD, "password");
        CURLcode res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        return (int)res;
    }
    return 1;
}