Select Page

Apache Maven copy local file to a remote server server using SSH

Apache Maven copy local file to a remote server server using SSH

I will show you in an Apache #Maven configuration file how to copy files to server each time the package phase is executed.

Solution with Ant SCP task

This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your #Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a #maven mvn package, you can add as many ant task and push to many server the same file during the reactor build.

                    <echo message="Push to server/home/"/>
                    <scp trust="yes" todir="user:[email protected]:/home/">
                        <fileset dir="${basedir}/target">
                            <include name="**/*.tar.gz"/>

Solution with #maven-deploy-plugin

The #maven-deploy-plugin allows you to configure the deploy phase to deploy to a server using scp. There is a page in the documentation that describes how it can be done.

Deploy #maven artifact using Maven Wagon SCP

Another alternative would be to use Maven Wagon SCP like described in this post for example

About The Author

Cédric Walter

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.