在CentOS系统中,使用SSH进行文件传输通常有两种方法:SCP(Secure Copy Protocol)和SFTP(SSH File Transfer Protocol)。以下是这两种方法的详细步骤:
方法一:使用SCP进行文件传输
1. 从本地计算机复制文件到远程CentOS服务器
scp /path/to/local/file username@remote_host:/path/to/remote/directory
/path/to/local/file是本地文件的路径。username是远程服务器的用户名。remote_host是远程服务器的IP地址或主机名。/path/to/remote/directory是远程服务器上的目标目录。
2. 从远程CentOS服务器复制文件到本地计算机
scp username@remote_host:/path/to/remote/file /path/to/local/directory
- 参数顺序与从本地复制到远程时相同,只是源路径和目标路径的位置互换。
3. 复制整个目录
scp -r /path/to/local/directory username@remote_host:/path/to/remote/directory
-r选项表示递归复制整个目录。
方法二:使用SFTP进行文件传输
1. 启动SFTP会话
sftp username@remote_host
- 这将启动一个SFTP会话,你将进入一个类似于FTP的命令行界面。
2. 在SFTP会话中进行文件传输
- 上传文件到远程服务器
put /path/to/local/file /path/to/remote/directory - 从远程服务器下载文件到本地
get /path/to/remote/file /path/to/local/directory - 上传整个目录
put -r /path/to/local/directory /path/to/remote/directory - 从远程服务器下载整个目录
get -r /path/to/remote/directory /path/to/local/directory
3. 退出SFTP会话
exit
注意事项
- 确保你有足够的权限访问远程服务器上的文件和目录。
- 使用SSH密钥认证可以提高安全性,避免每次连接时输入密码。
- 如果遇到权限问题,可以使用
sudo命令提升权限。
通过以上步骤,你可以在CentOS系统中使用SSH进行文件传输。