Java Code Examples for com.sshtools.j2ssh.SftpClient#get()

The following examples show how to use com.sshtools.j2ssh.SftpClient#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSHUtils.java    From stevia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Gets the file from remote host.
 *
 * @param host the hostname of the client
 * @param port the port number the user want to use for connection
 * @param username the username required for authentication
 * @param password the password required for authentication
 * @param remoteFilePath remotePath the remote path from where the file is going to be get
 * @param localfilePath the local file path where the file is going to be put
 * @param fileName the name of the file you want to transfer
 * @return the file from the remote host
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void getFileFromRemoteHost(String host, int port,String username,String password, String remoteFilePath,String localPath,String fileName) throws IOException {
	SftpClient sftp = getSftpClient(host, port,username, password);
	sftp.cd(remoteFilePath);
	sftp.lcd(localPath);
	sftp.get(fileName);
	File f = new File(localPath+System.getProperty("file.separator")+fileName);
	if (!f.exists()){
		SSH_LOG.error("The file " + fileName + " was not tranferred  to " + localPath);	
	}
	else{
		SSH_LOG.info("The file " + fileName + " was tranferred successfully to " + localPath);
	}		
}
 
Example 2
Source File: NetUtils.java    From ApprovalTests.Java with Apache License 2.0 5 votes vote down vote up
public static File sftpDownload(FTPConfig config, File file, String remoteFileName) throws IOException
{
  SshClient ssh = new SshClient();
  SftpClient sftp = sshLogin(config, ssh);
  sftp.get(remoteFileName, new FileOutputStream(file));
  sftp.quit();
  ssh.disconnect();
  return file;
}