I want to copy files from my local development environment (Win7, Eclipse, ANT) to a remote Ubuntu server. Ubuntu se开发者_高级运维ver locks root by default, so all copy commands require sudo cp ...
.
Is there a way to use ANT to accomplish this easily? I don't see any options for using SUDO, but I'm new to using ANT.
Install cygwin (cygwin.com) or mingw (mingw.org) and use scp/ssh from there. It's far easier to setup authorization there (you do it in $HOME/.ssh/ as usual) so that you do not have to pass it in the ant script.
When your local develop environment is on Windows you may use the Putty Client, a free Telnet/SSH client for Windows.Simply use the commandline tools plink, pscp, .. that Putty provides and use them within the Ant exec task.
see Putty Documentation for further details
plink => http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html#plink
Use SCP Task . This has dependency on jsch. I use this to copy files from windows to unix. It could probably copy from unix to windows (if windows is running ssh server)
I agree that it will be easy to do it with cygwin/mingw, but if you want to do everything in pure java, here is an example to exec sudo, http://www.jcraft.com/jsch/examples/Sudo.java
How about following ant tasks?
<scp todir="{$username}:{$password}@{$host}:/tmp/x" sftp="true">
<fileset dir="."/>
</scp>
<sshexec host="{$host}" username="{$username}" password="{$password}"
trust="yes" command="sudo -S -p '' mv /tmp/x /root/x"
input="/tmp/input"/>
, where "/tmp/input" will include the password for "sudo". If you use ant-1.8.3, you may want to use "inputstring" attribute.
精彩评论