hello,
i use commons-vfs for connect to a server in SSH and SFTP:
this is my code:
//connect to client server and return repository who contains flow
public FileObject connect() {
logger.debug("SSHReceiverConnect connect to : " + hostname);
ResourceBundle myConfig = ResourceBundle.getBundle("SSHReceiver");
String pass = (password == null ? "" : password);
FileSystemOptions opts = new FileSystemOptions();
try {
SftpFileSystemConfigBuilder.getInstance().setStric tHostKeyChecking(opts, "no");
// identities contains public Key client
File[] identities = new File[1];
identities[0] = new File(myConfig.getString(SSHConfigKeys.keyfile.name ()));
SftpFileSystemConfigBuilder.getInstance().setIdent ities(opts, identities);
StaticUserAuthenticator auth = new StaticUserAuthenticator(hostname, username, pass);
// we stock user infos in opts
DefaultFileSystemConfigBuilder.getInstance().setUs erAuthenticator(opts, auth);
// create connection with client server
// if no error we are connected to the server
logger.info("SSHReceiverConnect connect: CONNECTED to " + hostname);
FileSystemManager fsManager = VFS.getManager();
// we go to the flow path
String uriConnection = (password == null ? "sftp://" + username : "sftp://" + username + ":" + password);
uriConnection = (port == null ? uriConnection + "@" + hostname + path : "@" + hostname + ":" + port + path);
flowRepository = fsManager.resolveFile(uriConnection, opts);
return flowRepository;
} catch (FileSystemException e) {
logger.error("SSHReceiverConnect connect: FileSystemException -> NOT CONNECTED");
e.printStackTrace();
return null;
}
}
do you know what i have to do for disconnect?
because i don't use session to connect!!
thanks ;)