Skip to content
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

Remote FTP Cleanup throwing Exception #261

Closed
Sotiris-k opened this issue Sep 11, 2020 · 11 comments
Closed

Remote FTP Cleanup throwing Exception #261

Sotiris-k opened this issue Sep 11, 2020 · 11 comments
Assignees
Labels

Comments

@Sotiris-k
Copy link

Hello,

I'm using the remote FTP cleanup option as such

<sync type="ftp">
    <option name="host" value="backupServerHostHere"/>
    <option name="port" value="21"/>
    <option name="user" value="userHere"/>
    <option name="password" value="passHere"/>
    <option name="path" value="path/like/this/here"/>
    <option name="passive" value="true"/>
    <option name="cleanup.type" value="quantity"/>
    <option name="cleanup.amount" value="10"/>
</sync>

and I'm getting the following error

Exception 'phpbu\App\Backup\Sync\Exception' with message 'ftp_chdir(): Invalid number of parameters' in C:\Users\Sotiris\AppData\Roaming\Composer\vendor\phpbu\phpbu\src\Backup\Sync\Ftp.php:103

As you can see I'm using PHPBU on Windows but the FTP server is on Linux.

The files get uploaded just fine. It's just the remote cleanup that doesn't work.

Any thoughts?

@sebastianfeldmann
Copy link
Owner

sebastianfeldmann commented Sep 11, 2020

The only time ftp_chdir is called for remote cleanups is if a file should be deleted

ftp_chdir($connection, '');

This should not be necessary, so you can try to put a //in front of line 53 of vendor/phpbu/phpbu/src/Backup/File/Ftp.php to test if this fixes your issue.

It should look like this.

    /**
     * Deletes the file.
     *
     * @throws \phpbu\App\Exception
     */
    public function unlink()
    {
        try {
            //$this->ftpClient->chHome();
            $this->ftpClient->delete($this->pathname);
        } catch (\Exception $e) {
            throw new Exception($e->getMessage());
        }
    }

If this change will fix the issue I will make some further tests on my end and remove the chHome call.

@Sotiris-k
Copy link
Author

Sotiris-k commented Sep 11, 2020

Unfortunately this does not fix the issue. The error persists.

If I can be of any use to squash this bug, I'm all hands on deck :)

@sebastianfeldmann
Copy link
Owner

Are you using any dynamic path elements like /backups/%Y/%m/ or something similar?
I'm still struggling to find the actual call to chDir that causes the error on your side.

@Sotiris-k
Copy link
Author

Hi @sebastianfeldmann

Firstly, I really want to thank you for looking into this. I've been racking my brain with it for days.

My paths are all static. I've confirmed so far that it's a windows problem because with a linux stack it works fine.

Let me know if you need me to run any tests that you can think of!

@sebastianfeldmann
Copy link
Owner

No worries, happy to help if I can.
Do you have different PHP versions installed on Windows and Linux?
Because the FTP Lib has a >= PHP 7.2 hack in it.

@Sotiris-k
Copy link
Author

Sotiris-k commented Sep 21, 2020

On the Linux side where the FTP Server is, I've no idea what they're running because it's out of my control. I don't think it matters anyway.

On the Windows side, I have PHP 7.4.9 installed.

@sebastianfeldmann
Copy link
Owner

Just to get this right.
You are executing phpbu on Linux and it works.
You are executing phpbu on Windows and it "crashes" with your described error.

Is that what happens?

@Sotiris-k
Copy link
Author

Exactly.

@chland
Copy link

chland commented Dec 7, 2020

I've got the same problem when using phpbu on Windows 10 (PHP 7.2.31).

To see if i could figure out what's going on I wrote a small test-script that only connects to a ftp-server and then calls ftp_chdir('') - and it will always throw the exact same warning - which kinda make sense as the function expects a directory-name and an empty string is not really a valid directory-name (at least I couldn't find anything about calling CWD with an empty string to get to the home-directory).

I guess one way to fix it would be calling ftp_pwd after connecting to the remote server, store whatever path it returns as the home-directory and later use that stored value if chHome() is called.

Edit: I also tested it on a shared webhosting server running PHP 7.2.33 on Linux and it throws the same error. So it's not a windows/linux issue.

@fra81
Copy link

fra81 commented Feb 16, 2021

hello, same problem, tried from windows 10 (php 7.3 phpbu 6.0.14) to windows 2008 Gene6 FTP server, and from linux (php 7.0 with phpbu 5.2.10) to same FTP server

error message from phpbu is the same

Exception 'phpbu\App\Backup\Sync\Exception' with message ''
phpbu/phpbu.phar/Backup/Sync/Ftp.php:103 or phpbu.phar/Backup/Sync/Ftp.php:104

I could debug from server side log, I see in the case of windows phpbu 6.0.14 after the STOR (command ran ok), the command MLSD to retrieve the remote list of files (as I understand) from my configured remote folder diablo2.test, but return 550

image

and for linux case I see the command NLST

image

but seems no cleaner are done, as I configured amount:3 (type:quantity) and on the server there are more files present

@sebastianfeldmann
Copy link
Owner

I update the FTP implementation as @chland suggested. I now store the home directory on the initial connect and if chHome is called I use the previously stored value so it should not be called with the empty string anymore.

The PHAR is not yet updated, but I will do so ASAP.

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

No branches or pull requests

4 participants