ubuntu

Ubuntu如何用SSH传输大文件

小樊
41
2025-05-09 16:10:27
栏目: 智能运维

在Ubuntu中,使用SSH传输大文件可以通过多种方法实现,其中最常用的是scp(Secure Copy Protocol)和rsync命令。以下是这两种方法的详细步骤:

使用scp命令

  1. 安装scpscp通常已经预装在Ubuntu系统中,如果没有安装,可以使用以下命令安装:

    sudo apt update
    sudo apt install openssh-client
    
  2. 使用scp传输文件: 假设你要将本地文件/path/to/local/largefile.zip传输到远程服务器remote_host/path/to/remote/directory目录下,可以使用以下命令:

    scp /path/to/local/largefile.zip user@remote_host:/path/to/remote/directory/
    

    其中:

    • /path/to/local/largefile.zip 是本地文件的路径。
    • user 是远程服务器的用户名。
    • remote_host 是远程服务器的IP地址或主机名。
    • /path/to/remote/directory/ 是远程服务器上的目标目录。
  3. 传输过程中显示进度: 如果你想在传输过程中显示进度条,可以使用-v选项:

    scp -v /path/to/local/largefile.zip user@remote_host:/path/to/remote/directory/
    

使用rsync命令

  1. 安装rsyncrsync通常也已经预装在Ubuntu系统中,如果没有安装,可以使用以下命令安装:

    sudo apt update
    sudo apt install rsync
    
  2. 使用rsync传输文件: 假设你要将本地文件/path/to/local/largefile.zip传输到远程服务器remote_host/path/to/remote/directory目录下,可以使用以下命令:

    rsync -avz /path/to/local/largefile.zip user@remote_host:/path/to/remote/directory/
    

    其中:

    • -a 表示归档模式,保留所有文件属性。
    • -v 表示详细模式,显示传输过程中的详细信息。
    • -z 表示压缩数据在传输过程中。
  3. 断点续传rsync支持断点续传,如果传输过程中断,可以重新运行相同的命令,它会从上次中断的地方继续传输:

    rsync -avz /path/to/local/largefile.zip user@remote_host:/path/to/remote/directory/
    

注意事项

通过以上方法,你可以在Ubuntu系统中使用SSH高效地传输大文件。

0
看了该问题的人还看了