我可以使用 SSH 将文件夹压缩到托管 space 中吗?

Can I Zip a folder in hosting space using SSH?

我可以使用 SSH 和一些代码在托管 space 中压缩文件夹吗?

这是给客户的,所以我不能告诉他们使用 public keys/ putty/ commands/ ftp,我想给他们一个 url 例如 http://yourdomain.com/createbackup, 这样整个文件夹将被压缩并下载。

谢谢,任何帮助/指导将不胜感激。

和php。您可以使用 exec 和 linux 中的 tar command。 示例:

exec(tar -cvf sampleArchive.tar /home/sampleArchive);

仔细阅读此命令行,它将 运行 over linux 与后端中的 putty 相同

<?php
    
    header('Content-type: application/zip');
    
    
    $create_zip = shell_exec('sudo zip -r backup.zip FolderName');
    
   //backup.zip is your file , apply check this file does exit or not
   $zip_file='backup.zip';
    if(file_exists($zip_file)):
    
            header('Content-Disposition: attachment; filename="'.basename($zip_file).'"');
            header("Content-length: " . filesize($zip_file));
            header("Pragma: no-cache");
            header("Expires: 0");
    
        ob_clean();
            flush();
    
        readfile($zip_file);
    
        unlink($zip_file);
    
    else:
    echo 'Somthing went wrong please try again;'