【问题标题】:Ant SCP task through SSH connectionAnt SCP任务通过SSH连接
【发布时间】:2011-11-17 07:58:30
【问题描述】:

我希望能够将我的应用程序传输到开发服务器,但为了访问它,我首先必须通过 ssh 连接到 SSH 网关,然后通过 ssh 连接到内部网络到相应的服务器。我可以使用 Tunnel 选项对 WinSCP 执行此操作,我知道 ant 支持 SCP 任务,但它是否支持通过另一个 ssh 连接?

【问题讨论】:

    标签: java ant ssh scp


    【解决方案1】:

    有点丑陋的建议,但是您能否使用 scp 任务将您的应用程序部署到网关,然后使用 sshexec 任务在网关上运行脚本以将您的应用程序 scp 到下一个服务器?

    【讨论】:

    • 不,网关是这样设置的
    【解决方案2】:

    虽然这个问题并不新鲜,但我今天发现自己也遇到了类似的情况。我的目标是在我必须通过隧道(通过另一台服务器)连接的远程服务器上上传文件和运行命令。 蚂蚁也可以!

    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>
    

    【讨论】:

      猜你喜欢
      • 2011-02-19
      • 2011-09-15
      • 2023-03-09
      • 2014-10-19
      • 1970-01-01
      • 2012-10-16
      • 2014-09-03
      • 2017-12-04
      • 1970-01-01
      相关资源
      最近更新 更多