Access the remote server from ANT

czutshi
czutshi used Ask the Experts™
on
We need to move all latest java files from local machine to server using ANT.
How do we write buil.xml file?
Can someone please help us?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
That depends on what kind of access you have to the  server machine. If you have an FTP server on the remote machine, you can use an FTP task (http://ant.apache.org/manual/OptionalTasks/ftp.html).
If you access the remote machine using SSH telnet, you can use SCP, which does a secure copy over SSH (http://ant.apache.org/manual/OptionalTasks/scp.html).

Here a short snippet of the scp task (replace the ${} parts with the actual values). Note that if you do use SCP task you'll need ant-jsch.jar in your classpath (see http://stackoverflow.com/questions/2374105/ant-scp-task-not-working-even-with-jsch-on-ant-lib)

<scp todir="${scp.user}@${scp.host}:${scp.target.dir}" password="${scp.password}"
                   trust="true">
                  <fileset dir="${base.dir}/src" includes="**/*.java"/>
            </scp>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial