S
S
stamdyscias2017-01-05 02:26:32
C++ / C#
stamdyscias, 2017-01-05 02:26:32

Data transfer via ftp. How to do?

Hello everyone, in the program you need to transfer a .txt file via ftp to the server. C ++ language, here is something similar in python, but I didn’t find something like this in C ++:

import ftplib
 
host = "ftp.ex.ru"
ftp_user = "root"
ftp_password = "python"
filename = "picture.png"
 
con = ftplib.FTP(host, ftp_user, ftp_password)
# Открываем файл для передачи в бинарном режиме
f = open(filename, "rb")
# Передаем файл на сервер
send = con.storbinary("STOR "+ filename, f)
# Закрываем FTP соединение
con.close

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2017-01-05
@Mercury13

The most famous thing is cURL. In addition to FTP, it supports FTP+TLS and SFTP.
Here is an example for an FTP upload.
https://curl.haxx.se/libcurl/c/ftpupload.html
In C++ it's better to use "plus" wrappers for cURL, but the code is basically the same.

T
Tujh, 2017-01-09
@Tujh

If cross-platform is not required, then you can use the WinInet library. There, work with ftp will take lines 10-12 of code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question