centos

如何使用CentOS SFTP传输大文件

小樊
90
2025-02-13 09:57:49
栏目: 智能运维

在CentOS系统中,使用SFTP(SSH File Transfer Protocol)传输大文件可以通过以下步骤完成:

  1. 安装OpenSSH服务器: 如果你的CentOS系统还没有安装OpenSSH服务器,可以使用以下命令进行安装:

    sudo yum install openssh-server
    
  2. 启动并启用SSH服务: 确保SSH服务已经启动并设置为开机自启:

    sudo systemctl start sshd
    sudo systemctl enable sshd
    
  3. 配置防火墙: 如果你的CentOS系统启用了防火墙,确保允许SSH连接:

    sudo firewall-cmd --permanent --add-service=ssh
    sudo firewall-cmd --reload
    
  4. 连接到远程服务器: 使用SFTP客户端连接到远程服务器。你可以使用命令行工具sftp或者图形化客户端如FileZilla。

    sftp username@remote_host
    

    其中username是你的用户名,remote_host是远程服务器的IP地址或域名。

  5. 传输大文件

    • 上传文件: 使用put命令上传文件:

      put /path/to/local/large_file.zip
      

      这将把本地文件large_file.zip上传到远程服务器的当前目录。

    • 下载文件: 使用get命令下载文件:

      get /path/to/remote/large_file.zip /path/to/local/directory
      

      这将从远程服务器下载文件large_file.zip到本地目录。

  6. 使用SCP传输大文件: 如果你更喜欢使用SCP(Secure Copy Protocol),可以使用以下命令:

    • 上传文件
      scp /path/to/local/large_file.zip username@remote_host:/path/to/remote/directory
      
    • 下载文件
      scp username@remote_host:/path/to/remote/large_file.zip /path/to/local/directory
      
  7. 使用rsync传输大文件rsync是一个更强大的文件传输工具,特别适合传输大文件和目录:

    • 上传文件
      rsync -avz /path/to/local/large_file.zip username@remote_host:/path/to/remote/directory
      
    • 下载文件
      rsync -avz username@remote_host:/path/to/remote/large_file.zip /path/to/local/directory
      

通过以上步骤,你可以在CentOS系统中使用SFTP、SCP或rsync传输大文件。这些工具都支持断点续传,因此在传输大文件时非常有用。

0
看了该问题的人还看了