Feature: Callbacks for file operations
I hope that this library can monitor the FTP folder, such as add, update, delete files can have similar callback interface can be provided to need the function of the third party What do you think of this feature?
hm, this is supposed to be an FTP Server, not a filesystem watcher. What is your use case?
@Tinker-zzz you mean for the library to raise events based on FTP actions performed on the FTP server? like start of upload, finish of upload, etc ?
@ShaharHD Yes, that's exactly what I mean
@FlorianReimold I can add the ability to map async lambda function for events if you see it as a valid option.
I can make it as a method called after construction and before start (to map the lambda)
Reopeing this issue, as there seems to be some interest
@ShaharHD: What do you mean by async lambda function? Which thread will be executing them? Do you have a similar use case or are you interested in the implementation alone?
Reopeing this issue, as there seems to be some interest
@ShaharHD: What do you mean by async lambda function? Which thread will be executing them? Do you have a similar use case or are you interested in the implementation alone?
An automatictly created short lived thread for the async. The actual implementation is not affected by it.
My use case for it is to get events on the FTP server (which I can then act upon in my main application, in my case mailny progressing a FSM and updating statistics)
as far as async lambda - like so:
#include <iostream>
#include <future>
int main() {
auto async_lambda = std::async(std::launch::async, []() {
// Code to be executed asynchronously
std::cout << "Async lambda execution" << std::endl;
return 42;
});
// Perform other tasks while the lambda executes
// Get the result from the async lambda (this will block until the lambda is done)
int result = async_lambda.get();
std::cout << "Result from async lambda: " << result << std::endl;
return 0;
}
But it'll be a std::function in our case and you can set it before you start the service (like username and password)
OK, sounds reasonable. Can you make a proposal?
OK, sounds reasonable. Can you make a proposal?
@Tinker-zzz I was thinking on "download" and "upload" events - but I can go "full monty" here.
@FlorianReimold any reservations on this? I can match each "method" you have in the command_map with a proper event enum or select just specific commands for now.
For example: RETR, STOR and APPE with the filename
or also to include PASS with relevant std::shared_ptr<fineftp::FtpUser> or nullptr on failure ?
Hm, if you cover download and upload events, you also have to cover renaming, appending, deleting, creating directories etc., so that all filesystem operations can perform callbacks.
I think a signature like Callback(enum callback_type, ????) would simplify this a lot, so the user doesn't have to set dozens of callbacks.
You cannot pass std::shared_ptr<fineftp::FtpUser> to a callback, as that class is internal and must not be exposed to the public API.
I'll do a PR with initial offer next week - see how and if it fits your project design.