centos

centos sftp如何进行文件压缩与解压

小樊
39
2025-08-22 19:04:48
栏目: 智能运维

在CentOS系统中,使用SFTP进行文件压缩和解压通常涉及两个步骤:首先在本地计算机上压缩文件,然后通过SFTP将压缩文件传输到远程服务器;或者反过来,在远程服务器上压缩文件,然后将压缩文件传输到本地计算机。以下是详细步骤:

从本地计算机压缩并上传到远程服务器

  1. 在本地计算机上压缩文件

    • 使用ziptar命令压缩文件。
      zip -r archive.zip /path/to/directory
      # 或者
      tar -czvf archive.tar.gz /path/to/directory
      
  2. 通过SFTP上传压缩文件

    • 打开终端并启动SFTP会话。
      sftp username@remote_host
      
    • 输入密码后,进入SFTP命令模式。
    • 使用put命令上传压缩文件。
      put archive.zip /remote/path/
      # 或者
      put archive.tar.gz /remote/path/
      

从远程服务器下载并解压文件

  1. 通过SFTP下载压缩文件

    • 打开终端并启动SFTP会话。
      sftp username@remote_host
      
    • 输入密码后,进入SFTP命令模式。
    • 使用get命令下载压缩文件。
      get /remote/path/archive.zip /local/path/
      # 或者
      get /remote/path/archive.tar.gz /local/path/
      
  2. 在本地计算机上解压文件

    • 使用unziptar命令解压文件。
      unzip /local/path/archive.zip -d /destination/path/
      # 或者
      tar -xzvf /local/path/archive.tar.gz -C /destination/path/
      

在远程服务器上压缩并下载

  1. 在远程服务器上压缩文件

    • 登录到远程服务器。
      ssh username@remote_host
      
    • 使用ziptar命令压缩文件。
      zip -r archive.zip /path/to/directory
      # 或者
      tar -czvf archive.tar.gz /path/to/directory
      
  2. 通过SFTP下载压缩文件

    • 使用get命令下载压缩文件。
      get /path/to/archive.zip /local/path/
      # 或者
      get /path/to/archive.tar.gz /local/path/
      
  3. 在本地计算机上解压文件

    • 使用unziptar命令解压文件。
      unzip /local/path/archive.zip -d /destination/path/
      # 或者
      tar -xzvf /local/path/archive.tar.gz -C /destination/path/
      

通过以上步骤,你可以在CentOS系统中使用SFTP进行文件的压缩和解压操作。

0
看了该问题的人还看了