Linux scp命令用于Linux之间复制文件和目录
scp [可选参数] file_source file_target
1)本地到远程
A)文件
scp local_file remote_username@remote_host:remote_file
scp local_fle remote_host:remote_file
[root@localhost ~]# scp ./sh/corn.sh weizong@192.168.0.251:/home/weizong/
weizong@192.168.0.251's password:
corn.sh 100% 480 0.5KB/s 00:00
B)目录
scp -rv local_dir remote_username@remote_host:remote_dir
scp -rv local_dir remote_host:remote_dir
scp -rv /var/develop/ weizong@192.168.0.251:/home/weizong/
Executing: program /usr/bin/ssh host 192.168.0.251, user weizong, command scp -v -r -t /home/weizong/
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.0.251 [192.168.0.251] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.9p1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.0.251' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:3
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
weizong@192.168.0.251's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: scp -v -r -t /home/weizong/
Entering directory: D0755 0 develop
Sink: D0755 0 develop
Entering directory: D0755 0 c
Sink: D0755 0 c
Entering directory: D0755 0 miniFtp
Sink: D0755 0 miniFtp
Sending file modes: C0755 0 command.c
Sink: C0755 0 command.c
command.c 100% 0 0.0KB/s 00:00
Sending file modes: C0644 12288 .common.h.swp
Sink: C0644 12288 .common.h.swp
.common.h.swp 100% 12KB 12.0KB/s 00:00
Sending file modes: C0755 0 input.c
Sink: C0755 0 input.c
input.c 100% 0 0.0KB/s 00:00
Sending file modes: C0644 12288 .main.c.swp
Sink: C0644 12288 .main.c.swp
.main.c.swp 100% 12KB 12.0KB/s 00:00
Sending file modes: C0755 1254 common.h
Sink: C0755 1254 common.h
common.h 100% 1254 1.2KB/s 00:00
Entering directory: D0755 0 includes
Sink: D0755 0 includes
Sink: E
Sending file modes: C0755 0 main.c
Sink: C0755 0 main.c
main.c 100% 0 0.0KB/s 00:00
Sink: E
Sink: E
Entering directory: D0755 0 java
Sink: D0755 0 java
Sink: E
Sink: E
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.8 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
2)远程拉到本地
scp remote_host:remote_file local_file
scp remote_username@remote_host:remote_file local_file
目录同理参照传送到远程的翻转
可能有用的几个参数 :
-v 和大多数 linux 命令中的 -v 意思一样 , 用来显示进度 . 可以用来查看连接 , 认证 , 或是配置错误 .
-C 使能压缩选项 .
-P 选择端口 . 注意 -p 已经被 rcp 使用 .
-4 强行使用 IPV4 地址 .
-6 强行使用 IPV6 地址 .
Linux scp命令的使用方法应该可以满足大家对Linux文件和目录的复制使用了。
本文介绍了Linux scp命令的使用,包括从本地到远程以及从远程到本地的文件和目录拷贝。通过示例详细展示了scp命令的语法和常用参数,如-v(显示进度)、-C(启用压缩)、-P(选择端口)等,帮助用户在不同Linux主机间安全地传输文件。
860

被折叠的 条评论
为什么被折叠?



