现今的好多远程联接工具例如XShell或MobaXterm都有提供上传和下载的功能,除此之外,一些Linux终端的命令例如scp、sftp也可以实现这类功能,而且更为灵活和方便,不但可以满足本地与服务器之间的传输,也能在两台远程服务器之间互相传送文件。下边介绍scp的一些用法。
将本地文件复制到服务器
scp localmachine/path_to_the_file username@server_ip:/path_to_remote_directory
这儿的localmachine/path_to_the_file是本地文件的路径,username@server_ip是服务器的用户名和ip,前面接的是服务器上的路径。运行命令,输入服务器的登陆密码后redhat linux 下载,文件即被上传到了服务器/path_to_remote_directory的位置。
假如我们想复制整个文件夹中的内容到远程服务器呢?也十分简单,只须要加上一个参数-rlinux之间传文件,
scp -r localmachine/path_to_the_file username@server_ip:/path_to_remote_directory
从服务器复制文件到本地
若果是想获取服务器上的文件linux 常用命令,只须要对上述命令稍加更改:
scp username@server_ip:/path_to_remote_directory local_machine/path_to_the_file
同理,若果是获取服务器上的一个文件夹,也是加上参数-r:
scp -r username@server_ip:/path_to_remote_directory local_machine/path_to_the_file
复制服务器上的文件到另外一台服务器
假定我们没有登陆服务器linux之间传文件,想复制一台服务器中的文件到另外一台服务里面去:
scp username@server1_ip:/path_to_the_remote_fileusername@server2_ip:/path_to_destination_direcory/