/** * Copy a file from local computer to a remote computer * * @param vmIpAddress remote computer ip address * @param userName remote user * @param password remote password * @param localFile local file * @param remoteDir remote directory */ public void copyFile(String vmIpAddress, String userName, String password, String localFile, String remoteDir) { Scp scp = new Scp(); scp.setLocalFile(localFile); scp.setTodir(userName + ":" + password + "@" + vmIpAddress + ":" + remoteDir); scp.setProject(PROJECT); scp.setTrust(true); log.info("Copying {} to {} on {}", localFile, remoteDir, vmIpAddress); scp.execute(); }
@Override public void addFileset(final FileSet set) { if (fileSets == null) { fileSets = new ArrayList<>(); } fileSets.add(set); super.addFileset(set); }
@Override public SSHUserInfo getUserInfo() { return super.getUserInfo(); }
indexOfCurrentAt = uri.indexOf('@', indexOfCurrentAt + 1); setUsername(uri.substring(0, indexOfColon)); setPassword(uri.substring(indexOfColon + 1, indexOfAt)); } else if (indexOfAt > -1) { setUsername(uri.substring(0, indexOfAt)); } else { throw new BuildException("no username was given. Can't authenticate."); if (getUserInfo().getPassword() == null && getUserInfo().getKeyfile() == null) { throw new BuildException( "neither password nor keyfile for user %s has been given. Can't authenticate.", getUserInfo().getName()); setHost(uri.substring(indexOfAt + 1, indexOfPath)); String remotePath = uri.substring(indexOfPath + 1); if (remotePath.isEmpty()) {
private void mkdirAndCopyTo(String destination, Iterable<FileSet> sets) { if (Iterables.size(sets) == 0) { log("no content: " + destination, Project.MSG_DEBUG); return; } if (sshexec(exec("test -d " + destination).render(osFamily)) == 0) {// TODO windows log("already created: " + destination, Project.MSG_VERBOSE); return; } sshexec(exec("{md} " + destination).render(osFamily)); scp.init(); String scpDestination = getScpDir(destination); log("staging: " + scpDestination, Project.MSG_VERBOSE); for (FileSet set : sets) scp.addFileset(set); scp.setTodir(scpDestination); scp.execute(); }
@Override public void setTodir(final String aToUri) { this.toDir = aToUri; super.setTodir(aToUri); }
// This make scp copy of // one local file to remote dir org.apache.tools.ant.taskdefs.optional.ssh.Scp scp = new Scp(); int portSSH = 22; String srvrSSH = "ssh.your.domain"; String userSSH = "anyuser"; String pswdSSH = new String ( jPasswordField1.getPassword() ); String localFile = "C:\\localfile.txt"; String remoteDir = "/uploads/"; scp.setPort( portSSH ); scp.setLocalFile( localFile ); scp.setTodir( userSSH + ":" + pswdSSH + "@" + srvrSSH + ":" + remoteDir ); scp.setProject( new Project() ); scp.setTrust( true ); scp.execute();
public void setKnownhosts(String knownhosts) { this.knownhosts = knownhosts; super.setKnownhosts(knownhosts); }
/** * Remote host, either DNS name or IP. * * @param host * The new host value */ public void setHost(String host) { exec.setHost(host); scp.setHost(host); }
/** * Setting this to true trusts hosts whose identity is unknown. * * @param yesOrNo * if true trust the identity of unknown hosts. */ public void setTrust(boolean yesOrNo) { exec.setTrust(yesOrNo); scp.setTrust(yesOrNo); userInfo.setTrust(yesOrNo); }
@Override public void setProject(Project project) { super.setProject(project); exec.setProject(project); scp.setProject(project); }
/** * Sets the password for the user. * * @param password * The new password value */ public void setPassword(String password) { exec.setPassword(password); scp.setPassword(password); userInfo.setPassword(password); }
/** * Sets the path to the file that has the identities of all known hosts. This is used by SSH * protocol to validate the identity of the host. The default is * <i>${user.home}/.ssh/known_hosts</i>. * * @param knownHosts * a path to the known hosts file. */ public void setKnownhosts(String knownHosts) { exec.setKnownhosts(knownHosts); scp.setKnownhosts(knownHosts); }