首页 > 解决方案 > 我可以使用 SSH 压缩托管空间中的文件夹吗?

问题描述

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

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

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

标签: javascriptphpsshserverhosting

解决方案


仔细阅读这个命令行,它将在 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;'

推荐阅读