Remote command unzip

Discussion in 'Server Operation' started by PMTeurope, Apr 1, 2024.

  1. PMTeurope

    PMTeurope New Member

    Is it possible to unzip a file on server side with ftp?
    In winscp the "remote command" options are gray
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The FTP protocol does not allow to run commands. Create an SSH user instead and connect with SCP or SFTP.
     
    michelangelo likes this.
  3. michelangelo

    michelangelo Active Member

    As Till already said it, either SSH/SFTP or alternatively you could write a PHP file that unpacks your file when you open it via the browser.
     
  4. PMTeurope

    PMTeurope New Member

    The tip of the php way works great.

    For everybody who want to do it also, here the code
    Make a unzip.php file with the code below in it. Place the file in the directory where you want to unzip it and run the file in your browser. Thats all.


    PHP:
    <?php

    // assuming file.zip is in the same directory as the executing script.
    $file 'file.zip';

    // get the absolute path to $file
    $path pathinfo(realpath($file), PATHINFO_DIRNAME);

    $zip = new ZipArchive;
    $res $zip->open($file);
    if (
    $res === TRUE) {
      
    // extract it to the path we determined above
      
    $zip->extractTo($path);
      
    $zip->close();
      echo 
    "WOOT! $file extracted to $path";
    } else {
      echo 
    "Doh! I couldn't open $file";
    }
    ?>
     
    Last edited: Apr 2, 2024
    ahrasis likes this.

Share This Page