Skip to content

Feature: Callbacks for file operations #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tinker-zzz opened this issue Jun 26, 2024 · 10 comments
Open

Feature: Callbacks for file operations #69

Tinker-zzz opened this issue Jun 26, 2024 · 10 comments

Comments

@Tinker-zzz
Copy link

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?

@FlorianReimold
Copy link
Member

hm, this is supposed to be an FTP Server, not a filesystem watcher. What is your use case?

@ShaharHD
Copy link
Contributor

@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 ?

@Tinker-zzz
Copy link
Author

@ShaharHD Yes, that's exactly what I mean

@ShaharHD
Copy link
Contributor

ShaharHD commented Jan 30, 2025

@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)

@FlorianReimold FlorianReimold reopened this Feb 5, 2025
@FlorianReimold FlorianReimold changed the title New feature requirements Callbacks for file operations Feb 5, 2025
@FlorianReimold FlorianReimold changed the title Callbacks for file operations Feature: Callbacks for file operations Feb 5, 2025
@FlorianReimold
Copy link
Member

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?

@ShaharHD
Copy link
Contributor

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)

@FlorianReimold
Copy link
Member

OK, sounds reasonable. Can you make a proposal?

@ShaharHD
Copy link
Contributor

ShaharHD commented Feb 13, 2025

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 ?

@FlorianReimold
Copy link
Member

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.

@ShaharHD
Copy link
Contributor

ShaharHD commented Feb 18, 2025

I'll do a PR with initial offer next week - see how and if it fits your project design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants