lazzard / php-ftp-client

:package: Provides helper classes and methods to manage FTP files in an OOP way.
MIT License
90 stars 18 forks source link

Are directories and their contents not being loaded from local to remote server? #44

Closed Ademgenc53 closed 12 months ago

Ademgenc53 commented 1 year ago

Hello,

I'm new to php Can I transfer all the contents without a local directory path example "../test_directory" to the main directory of the ftp account on the remote server "test_directory"? AND Can I see the results of simultaneously transferred files on the screen as "the file is successful"?

Thank you

AmraniCh commented 1 year ago

Hey! Yes you do this but I don't think you can achieve the results you said using this library unless you do some additional logic, If you want to print a message on the screen every time a file is copied from local to a remote file, you have to iterate on the local directory files on yourself, and for every file use the copyFromLocal method to transfer it to the proper remote directory, when the copyFromLocal returns true you can now use output flushing and buffering to print a message on the screen.

Ademgenc53 commented 1 year ago

Thanks for the answer, Did you mean, We will create a directory scanning/directory content listing loop and use copyFromLocal() instead of ftp_put(). Did I get right.

AmraniCh commented 12 months ago

Yes you did, copyFromLocalmethod is just a wrapper for the built-in PHP function ftp_put or ftp_fput if you have already an opening file pointer, so yes iterate over the local directory and use copyFromLocalmethod to upload each file, and once the method returns true that means the file is successfully uploaded to the remote directory, and now use output buffering to send message to the output stream and flush the buffer after that, like this:

ob_end_clean();
ob_start();

echo "file 'name or path of the file' is success!";

ob_flush();
flush();