两台服务器之间进行 scp 时如何使用 IPV4?

两台服务器之间进行 scp 时如何使用 IPV4?

我想scp从本地计算机运行命令将文件从 host1 复制到 host2。从主机 1 到主机 2 的连接必须使用 IPV4,因为主机 1 和主机 2 之间没有 IPV6 连接(由于我无法控制的原因)。

在我的本地机器上,我使用:

scp -4 -v -r -o "ForwardAgent=yes" user@host1:myFile user@host2:

在输出中,我有:

debug1: Connecting to host1 [a.b.c.d] port 22.

这是正确的,但尝试使用 IPV6 从主机 1 到主机 2 进行连接:

debug1: Connecting to host2 [a:b:c:d:e:f:g:h] port 22

但它失败了,因为没有 IPv6 连接。

如何强制 scp 在从 host1 到 host2 的连接上使用 IPV4?

PS:我使用的scp是macOS 10.13.3

==== 编辑

下面是完整的日志。您可以看到问题来自于以下事实:当 scp 从 host1 发送命令时,它没有添加该-4选项。请参阅该行:

debug1: Sending command: scp -v -r /myFile user@host2:.

OpenSSH_7.6p1, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /Users/user/.ssh/config
debug1: /Users/user/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /usr/local/etc/ssh/ssh_config
debug1: Connecting to host1 [a.b.c.d] port 22.
debug1: Connection established.
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Debian-10+deb9u3
debug1: match: OpenSSH_7.4p1 Debian-10+deb9u3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to host1:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:/sfbwfbhwh/wsfgwhwthwth
debug1: Host 'host1' is known and matches the ECDSA host key.
debug1: Found key in /Users/user/.ssh/known_hosts:66
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to host1.com ([a.b.c.d]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Requesting authentication agent forwarding.
debug1: Sending command: scp -v -r /myFile user@host2:.
Executing: program /usr/bin/ssh host host2, user user, command scp -v -r -t .
OpenSSH_7.4p1 Debian-10+deb9u3, OpenSSL 1.0.2l  25 May 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to host2 [a:b:c:d:e:f:g:h] port 22.

答案1

尝试使用 ::scp -4 -v -r -o "ForwardAgent=yes" user@host1:myFile [email protected]

其中 defg 是主机 2 的 IPv4 地址。请检查您的 DNS,以便它返回正确的地址。

答案2

这应该可以做到。希望我正确理解你:)

$ rsync -rav --ipv4 /tmp/f.txt  someuser@dev1:/home/someuser

man rsync

 -v, --verbose               increase verbosity
 -a, --archive               archive mode; same as -rlptgoD (no -H)
 -r, --recursive             recurse into directories
 -4, --ipv4                  prefer IPv4

相关内容