开发者

Ant SCP task through SSH connection

开发者 https://www.devze.com 2023-04-05 10:17 出处:网络
I want to be able to transfer my application to the development server but in order to access it I first have to ssh to an SSH gateway and then ssh into the internal network to t开发者_运维问答he appr

I want to be able to transfer my application to the development server but in order to access it I first have to ssh to an SSH gateway and then ssh into the internal network to t开发者_运维问答he appropriate server. I can do this with WinSCP using the Tunnel option, I know that ant supports SCP tasks but does it support it over another ssh connection?


Kind of an ugly suggestion, but could you use the scp task to get your app deployed to the gateway and then use the sshexec task to run a script on the gateway to scp your application to the next server?


Although this question is not exactly new, I found myself in a similar situation today. My goal is to upload files and run commands on a remote server to which I have to tunnel (through another server). And it is possible with ant!

The sshsession only creates a tunnel that you can use for the tasks within. The tasks within are not automatically run on the remote server but you can use the sshexec task together with the tunnel to achieve that. Also the scp task can now upload through the tunnel to the remote server. Here is an example:

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号