embeddedmz / ftpclient-cpp

C++ client for making FTP requests
MIT License
204 stars 65 forks source link

Linux-Ubuntu:Upload file to FTP server #49

Closed aframatilda closed 1 year ago

aframatilda commented 1 year ago

Hi! I want to upload an image from C++ project to a ftp server. I have created an upload function in c++ and I am working in Ubuntu Linux. The FtpClient.h file is located in my include folder, but I get "fatal error: direct.h: No such file or directory 23 | #include // mkdir".

See my code below. The param argument is a string path to the image. How should I work further? Thanks in advance!

void upload(std::string& param)
{
void(const std::string&)
    CFTPClient FTPClient([](const std::string& strLogMsg){ std::cout << strLogMsg << std::endl; });
    FTPClient.InitSession("host", port, "user", "password");
    FTPClient.SetActive(true);
    FTPClient.UploadFile("C:/Desktop/upload.txt", "/ftp_folder/test_upload.txt");
    FTPClient.CleanupSession();
}
embeddedmz commented 1 year ago

Hi,

You need to set a preprocessor macro named LINUX. You can do it by using a compiler argument (g++ .... -DLINUX) or like this (before inclusion)

#define LINUX
#include "ftpclient.h"

In fact, is a header that is only available when compiling using Visual Studio C++ compiler on Windows. In ftpclient.cpp, you can see that I use a macro named WINDOWS to hide some code intended for Windows when compiling on Linux.

The CMake build scripts take care of that but since you don't want to use CMake you have to define LINUX macro when using the class on Linux.