通过 SSH 连接的 Ant SCP 任务

发布于 2024-12-04 14:51:12 字数 140 浏览 0 评论 0原文

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

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 the 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请持续率性 2024-12-11 14:51:12

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

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?

毁梦 2024-12-11 14:51:12

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

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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文