@Override protected void doCloseCommunicationLink() { if ( this.session != null ) { this.session.disconnect(); this.session = null; } super.doCloseCommunicationLink(); }
/** * Ensures that the session link is established. * * @throws FileSystemException if a session cannot be created. */ private void ensureSession() throws FileSystemException { if (this.session == null || !this.session.isConnected()) { doCloseCommunicationLink(); // channel closed. e.g. by freeUnusedResources, but now we need it again Session session; UserAuthenticationData authData = null; try { final GenericFileName rootName = (GenericFileName) getRootName(); authData = UserAuthenticatorUtils.authenticate(getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())), getFileSystemOptions()); } catch (final Exception e) { throw new FileSystemException("vfs.provider.sftp/connect.error", getRootName(), e); } finally { UserAuthenticatorUtils.cleanup(authData); } this.session = session; } }
/** * Ensures that the session link is established. * * @throws FileSystemException if a session cannot be created. */ private void ensureSession() throws FileSystemException { if (this.session == null || !this.session.isConnected()) { doCloseCommunicationLink(); // channel closed. e.g. by freeUnusedResources, but now we need it again Session session; UserAuthenticationData authData = null; try { final GenericFileName rootName = (GenericFileName) getRootName(); authData = UserAuthenticatorUtils.authenticate(getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())), getFileSystemOptions()); } catch (final Exception e) { throw new FileSystemException("vfs.provider.sftp/connect.error", getRootName(), e); } finally { UserAuthenticatorUtils.cleanup(authData); } this.session = session; } }
/** * Ensures that the session link is established. * * @throws FileSystemException if a session cannot be created. */ private void ensureSession() throws FileSystemException { if (this.session == null || !this.session.isConnected()) { doCloseCommunicationLink(); // channel closed. e.g. by freeUnusedResources, but now we need it again Session session; UserAuthenticationData authData = null; try { final GenericFileName rootName = (GenericFileName) getRootName(); authData = UserAuthenticatorUtils.authenticate(getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())), getFileSystemOptions()); } catch (final Exception e) { throw new FileSystemException("vfs.provider.sftp/connect.error", getRootName(), e); } finally { UserAuthenticatorUtils.cleanup(authData); } this.session = session; } }