【发布时间】:2011-11-17 07:58:30
【问题描述】:
我希望能够将我的应用程序传输到开发服务器,但为了访问它,我首先必须通过 ssh 连接到 SSH 网关,然后通过 ssh 连接到内部网络到相应的服务器。我可以使用 Tunnel 选项对 WinSCP 执行此操作,我知道 ant 支持 SCP 任务,但它是否支持通过另一个 ssh 连接?
【问题讨论】:
我希望能够将我的应用程序传输到开发服务器,但为了访问它,我首先必须通过 ssh 连接到 SSH 网关,然后通过 ssh 连接到内部网络到相应的服务器。我可以使用 Tunnel 选项对 WinSCP 执行此操作,我知道 ant 支持 SCP 任务,但它是否支持通过另一个 ssh 连接?
【问题讨论】:
有点丑陋的建议,但是您能否使用 scp 任务将您的应用程序部署到网关,然后使用 sshexec 任务在网关上运行脚本以将您的应用程序 scp 到下一个服务器?
【讨论】:
虽然这个问题并不新鲜,但我今天发现自己也遇到了类似的情况。我的目标是在我必须通过隧道(通过另一台服务器)连接的远程服务器上上传文件和运行命令。 蚂蚁也可以!
sshsession 只创建一个隧道,您可以将其用于其中的任务。其中的任务不会自动在远程服务器上运行,但您可以使用 sshexec 任务和 tunnel 来实现。此外,scp 任务现在可以通过隧道上传到远程服务器。这是一个例子:
<sshsession host="${jumphost}" port="22" username="${user}" password="${password}" trust="true">
<localtunnel lport="${localTunnelPort}" rhost="${targethost}" rport="22"/>
<sequential>
<!-- run a command on the remote server (here mkdir) -->
<sshexec host="localhost" port="${localTunnelPort}" username="${user.param}" password="${password.param}" command="mkdir ${home}/foobar" trust="true" />
<!-- upload a file to the remote server -->
<scp port="${localTunnelPort}" file="test_file.txt" todir="${user.param}:${password.param}@localhost:${home}/foobar/" trust="true" />
</sequential>
</sshsession>
【讨论】: