I wrote a simple script to zip whole folder on ftp. I connect to this through ftp protocol, and I found it difficult to zip and unzip anything this way, so decided to use php as shell turned out to be too difficult for me. I run script bellow by bat file, it looks like that:

open ftp…….
cd domains/tmp.hekko24.pl/public_html
echo '<?php system("zip -r folder1.zip folder1") ?>' | php -q

Connection and patch is ok because I was using this to remove files (rm) and it works then. Also when I try to run this php script in a php file through browser, then it works so system() function is available at my hosting. Bellow is log, and there is nothing so I have no idea why it doesn’t work.

. 2019-04-28 19:37:12.074 Using FTP protocol.
. 2019-04-28 19:37:12.074 Doing startup conversation with host.
> 2019-04-28 19:37:12.074 PWD
< 2019-04-28 19:37:12.095 257 "/" is the current directory
. 2019-04-28 19:37:12.095 Getting current directory name.
. 2019-04-28 19:37:12.095 Startup conversation with host finished.
< 2019-04-28 19:37:12.095 Script: Aktywna sesja: [1] xxxxxxx@xxxxxxxxxx
> 2019-04-28 19:37:12.099 Script: cd domains/tmp.hekko24.pl/public_html
. 2019-04-28 19:37:12.099 Cached directory change via "domains/tmp.hekko24.pl/public_html" to "/domains/tmp.hekko24.pl/public_html".
. 2019-04-28 19:37:12.099 Getting current directory name.
< 2019-04-28 19:37:12.099 Script: /domains/tmp.hekko24.pl/public_html
> 2019-04-28 19:37:12.103 Script: echo '<?php system("zip -r folder1.zip folder1") ?>' | php -q
< 2019-04-28 19:37:12.103 Script: '<?php system("zip -r folder1.zip folder1") ?>' | php -q
> 2019-04-28 19:37:12.106 Script: exit
. 2019-04-28 19:37:12.106 Script: Exit code: 0
. 2019-04-28 19:37:12.109 Rozłączono z serwerem
  • You can't execute php code in ftp session, but as a workaround you could create a small php script and trigger "unzip" from your browser. See How to unzip files via an FTP connection?. Or if you have a ssh login, you could login, change to the directory, unzip the file and logout. The latter can be scripted.
    – Freddy
    Apr 29 '19 at 16:46
  • Thank you for your reply, I read it but still cannot find how to "hit url" with this php script when I am connected through ftp. I have ssh login, so maybe it will be easier to write shell script, winscp and ftp connection doesn't seem to be proper tool for that (I have 90 folders to backup separately, so must have some automatization).
    – Konrad
    May 2 '19 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.