Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Ant for ssh and scp operations

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to use Ant for ssh and scp operations, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Use Ant for ssh and scp operations

I. brief introduction:

Now when we install Linux, we usually do not open the telnet service for security reasons (by default), and there are ssh services. Ant supports telnet a long time ago, but requires us to install telnet-server under Linux and enable the service.

Fortunately, SSH and SCP operations have been supported since Ant1.60. Long before Ant, if you want to support SSH, SCP, SFTP and other tasks, you must download j2ssh's j2ssh-ant.jar and j2ssh-core.jar (available under http://www.sourceforge.net 's j2ssh). You can now use the Sshexec and scp tasks provided by Ant, supported by $ANT_HOME/lib/ant-jsch.jar, but you also need to download a dependency package jsch-0.1.24.jar (the file name varies from version to version) in http://www.jcraft.com/jsch/index.html, and jsch is also a project under http://www.sourceforge.net.

You need to copy the downloaded jsch-0.1.24 to $ANT_HOME/lib. For the Ant environment under Eclipse, you must add jsch-0.1.24 in Window- > Preferences- > Ant- > Runtime- > Classpath.

JSch is a pure Java implementation of SSH2

JSch allows you to connect to sshd server and use port mapping, X11 mapping, Scp file transfer, etc., you can integrate the functions provided by JSch into your own Java project, JSch authorization is in the form of BSD.

2. Simple examples:

The following is the simplest example of using JSch to complete both Sshexec and scp tasks. If you need more details, please refer to the Ant user manual.

[Sshexec task]

Note that the above trust property is generally set to true, if it is the default value of false, then the host you are connected to must exist in your knownhosts file, and the file must also exist, otherwise there will be an exception of com.jcraft.jsch.JSchException: reject HostKey: 192.168.122.180. When executing commands under Linux, you can use semicolons to separate multiple commands, and they will be executed in turn, instead of writing multiple sshexec to connect multiple times, executing only one command per connection.

[scp task]

1. Copy a single file to a remote server

Or

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report