@Override protected void doCloseCommunicationLink() { if ( this.session != null ) { this.session.disconnect(); this.session = null; } super.doCloseCommunicationLink(); }
@Override protected boolean doIsReadable() throws Exception { SftpFileSystemWindows fileSystem = (SftpFileSystemWindows) getAbstractFileSystem(); if ( !fileSystem.isRemoteHostWindows() ) { return super.doIsReadable(); } else { List<String> userGroups = fileSystem.getUserGroups(); Map<String, String> filePermissions = fileSystem.getFilePermission( this.path ); for ( String group : userGroups ) { String acl = filePermissions.get( group ); if ( acl != null ) { return acl.contains( FULL_ACCESS ) || acl.contains( MODIFY_ACCESS ) || acl.contains( READ_AND_EXECUTE_ACCESS ) || acl.contains( READ_ACCESS ) || acl.contains( WRITE_ACCESS ) || acl.contains( WRITE_DATA_ADD_FILES_ACCESS ) || acl.contains( READ_DATA_ADD_FILES_ACCESS ); } } return false; } }
@Override protected boolean doIsWriteable() throws Exception { SftpFileSystemWindows fileSystem = (SftpFileSystemWindows) getAbstractFileSystem(); if ( !fileSystem.isRemoteHostWindows() ) { return super.doIsWriteable(); } else { List<String> userGroups = fileSystem.getUserGroups(); Map<String, String> filePermissions = fileSystem.getFilePermission( this.path ); for ( String group : userGroups ) { String acl = filePermissions.get( group ); if ( acl != null ) { return acl.contains( FULL_ACCESS ) || acl.contains( MODIFY_ACCESS ) || acl.contains( WRITE_ACCESS ) || acl.contains( WRITE_DATA_ADD_FILES_ACCESS ); } } return false; } }
/** * Constructs a new provider. */ public SftpFileProvider() { super(); setFileNameParser(SftpFileNameParser.getInstance()); }
FileNameParser sftpFilenameParser = SftpFileNameParser.getInstance(); URLFileName file = (URLFileName) sftpFilenameParser.parseUri( null, null, vfsUrl ); identities = new IdentityInfo[] { new IdentityInfo( new File( value ) ) }; } else { identities = temp; identities[identities.length - 1] = new IdentityInfo( new File( value ) );
/** * {@link org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() } * */ private void ensureSession() throws FileSystemException { if ( this.session == null || !this.session.isConnected() ) { this.doCloseCommunicationLink(); UserAuthenticationData authData = null; Session session; try { GenericFileName e = (GenericFileName) this.getRootName(); authData = UserAuthenticatorUtils.authenticate( this.getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES ); session = SftpClientFactory.createConnection( e.getHostName(), e.getPort(), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar( e.getUserName() ) ), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar( e.getPassword() ) ), this.getFileSystemOptions() ); } catch ( Exception var7 ) { throw new FileSystemException( "vfs.provider.sftp/connect.error", this.getRootName(), var7 ); } finally { UserAuthenticatorUtils.cleanup( authData ); } this.session = session; } }
/** * Configures authentication order. * * @param opts The FileSystem options. * @param preferredAuthentications The authentication order. * @since 2.0 */ public void setPreferredAuthentications(final FileSystemOptions opts, final String preferredAuthentications) { this.setParam(opts, PREFERRED_AUTHENTICATIONS, preferredAuthentications); }
/** * <p>In case it's impossible to determine the actual permissions, returns an "always-true" permission.</p> * * @param checkIds * @return * @throws Exception */ @Override protected PosixPermissions getPermissions( boolean checkIds ) throws Exception { if ( checkIds && ( getAbstractFileSystem() instanceof SftpFileSystemWindows ) && ( (SftpFileSystemWindows) getAbstractFileSystem() ).isExecDisabled() ) { // Exec is disabled, so we won't be able to ascertain the current user's UID and GID. // Return "always-true" permissions as a workaround, knowing that the SFTP server won't // let us perform unauthorized actions anyway. return new PretendUserIsOwnerPosixPermissions(); } return super.getPermissions( checkIds ); }
/** * @param opts The FileSystem options. * @return The names of the compression algorithms, comma-separated. * @see #setCompression */ public String getCompression(final FileSystemOptions opts) { return this.getString(opts, COMPRESSION); }
/** * Called after the stream has been closed. */ @Override protected void onClose() throws IOException { getAbstractFileSystem().putChannel(channel); } }
/** * Gets the proxy-port to use for the SFTP the connection. * * @param opts The FileSystem options. * @return proxyPort: the port number or 0 if it is not set * @see #setProxyPort * @see #getProxyHost */ public int getProxyPort(final FileSystemOptions opts) { return this.getInteger(opts, PROXY_PORT, 0); }
/** * Constructs a new provider. */ public SftpFileProvider() { super(); setFileNameParser(SftpFileNameParser.getInstance()); }
/** * Sets the proxy username to use for the SFTP connection. * * @param opts The FileSystem options. * @param proxyOptions the options * @see #getProxyOptions * @since 2.1 */ public void setProxyOptions(final FileSystemOptions opts, final FileSystemOptions proxyOptions) { this.setParam(opts, PROXY_OPTIONS, proxyOptions); }
/** * Gets the file name encoding. * * @param opts The FileSystem options. * @return the file name encoding */ public String getFileNameEncoding(final FileSystemOptions opts) { return this.getString(opts, ENCODING); }
/** * Constructs a new provider. */ public SftpFileProvider() { super(); setFileNameParser(SftpFileNameParser.getInstance()); }
/** * Sets the file name encoding. * * @param opts The FileSystem options. * @param fileNameEncoding The name of the encoding to use for file names. */ public void setFileNameEncoding(final FileSystemOptions opts, final String fileNameEncoding) { this.setParam(opts, ENCODING, fileNameEncoding); }
/** * @param opts The FileSystem options. * @return the option value The host key checking. * @see #setStrictHostKeyChecking(FileSystemOptions, String) */ public String getStrictHostKeyChecking(final FileSystemOptions opts) { return this.getString(opts, STRICT_HOST_KEY_CHECKING, HOST_KEY_CHECK_NO); }
/** * Constructs a new provider. */ public SftpFileProvider() { super(); setFileNameParser(SftpFileNameParser.getInstance()); }
/** * Sets the proxy to use for the SFTP connection. * * You MUST also set the proxy port to use the proxy. * * @param opts The FileSystem options. * @param proxyHost the host * @see #setProxyPort */ public void setProxyHost(final FileSystemOptions opts, final String proxyHost) { this.setParam(opts, PROXY_HOST, proxyHost); }
/** * Sets the proxy username to use for the SFTP connection. * * @param opts The FileSystem options. * @param proxyOptions the options * @see #getProxyOptions * @since 2.1 */ public void setProxyOptions(final FileSystemOptions opts, final FileSystemOptions proxyOptions) { this.setParam(opts, PROXY_OPTIONS, proxyOptions); }