idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
11,900
public boolean isCharacter ( ) { if ( permissions != null && ( permissions . longValue ( ) & SftpFileAttributes . S_IFCHR ) == SftpFileAttributes . S_IFCHR ) { return true ; } return false ; }
Determine whether these attributes refer to a character device .
11,901
public boolean isSocket ( ) { if ( permissions != null && ( permissions . longValue ( ) & SftpFileAttributes . S_IFSOCK ) == SftpFileAttributes . S_IFSOCK ) { return true ; } return false ; }
Determine whether these attributes refer to a socket .
11,902
public static Provider getProviderForAlgorithm ( String jceAlgorithm ) { if ( specficProviders . containsKey ( jceAlgorithm ) ) { return ( Provider ) specficProviders . get ( jceAlgorithm ) ; } return defaultProvider ; }
Get the provider for a specific algorithm .
11,903
public static SecureRandom getSecureRandom ( ) throws NoSuchAlgorithmException { if ( secureRandom == null ) { try { return secureRandom = JCEProvider . getProviderForAlgorithm ( JCEProvider . getSecureRandomAlgorithm ( ) ) == null ? SecureRandom . getInstance ( JCEProvider . getSecureRandomAlgorithm ( ) ) : SecureRand...
Get the secure random implementation for the API .
11,904
public boolean containsFile ( File f ) { return unchangedFiles . contains ( f ) || newFiles . contains ( f ) || updatedFiles . contains ( f ) || deletedFiles . contains ( f ) || recursedDirectories . contains ( f ) || failedTransfers . containsKey ( f ) ; }
Determine whether the operation contains a file .
11,905
public boolean containsFile ( SftpFile f ) { return unchangedFiles . contains ( f ) || newFiles . contains ( f ) || updatedFiles . contains ( f ) || deletedFiles . contains ( f ) || recursedDirectories . contains ( f . getAbsolutePath ( ) ) || failedTransfers . containsKey ( f ) ; }
Determine whether the directory operation contains an SftpFile
11,906
public void addDirectoryOperation ( DirectoryOperation op , File f ) { addAll ( op . getUpdatedFiles ( ) , updatedFiles ) ; addAll ( op . getNewFiles ( ) , newFiles ) ; addAll ( op . getUnchangedFiles ( ) , unchangedFiles ) ; addAll ( op . getDeletedFiles ( ) , deletedFiles ) ; Object obj ; for ( Enumeration e = op . f...
Add the contents of another directory operation . This is used to record changes when recuring through directories .
11,907
public long getTransferSize ( ) throws SftpStatusException , SshException { Object obj ; long size = 0 ; SftpFile sftpfile ; File file ; for ( Enumeration e = newFiles . elements ( ) ; e . hasMoreElements ( ) ; ) { obj = e . nextElement ( ) ; if ( obj instanceof File ) { file = ( File ) obj ; if ( file . isFile ( ) ) {...
Get the total number of bytes that this operation will transfer
11,908
public void writeBigInteger ( BigInteger bi ) throws IOException { byte [ ] raw = bi . toByteArray ( ) ; writeInt ( raw . length ) ; write ( raw ) ; }
Write a BigInteger to the array .
11,909
public void writeInt ( long i ) throws IOException { byte [ ] raw = new byte [ 4 ] ; raw [ 0 ] = ( byte ) ( i >> 24 ) ; raw [ 1 ] = ( byte ) ( i >> 16 ) ; raw [ 2 ] = ( byte ) ( i >> 8 ) ; raw [ 3 ] = ( byte ) ( i ) ; write ( raw ) ; }
Write an integer to the array
11,910
public static byte [ ] encodeInt ( int i ) { byte [ ] raw = new byte [ 4 ] ; raw [ 0 ] = ( byte ) ( i >> 24 ) ; raw [ 1 ] = ( byte ) ( i >> 16 ) ; raw [ 2 ] = ( byte ) ( i >> 8 ) ; raw [ 3 ] = ( byte ) ( i ) ; return raw ; }
Encode an integer into a 4 byte array .
11,911
public void writeString ( String str , String charset ) throws IOException { if ( str == null ) { writeInt ( 0 ) ; } else { byte [ ] tmp ; if ( ByteArrayReader . encode ) tmp = str . getBytes ( charset ) ; else tmp = str . getBytes ( ) ; writeInt ( tmp . length ) ; write ( tmp ) ; } }
Write a String to the byte array converting the bytes using the given character set .
11,912
public void initialize ( ) throws SshException , UnsupportedEncodingException { try { Packet packet = createPacket ( ) ; packet . write ( SSH_FXP_INIT ) ; packet . writeInt ( this_MAX_VERSION ) ; sendMessage ( packet ) ; byte [ ] msg = nextMessage ( ) ; if ( msg [ 0 ] != SSH_FXP_VERSION ) { close ( ) ; throw new SshExc...
Initializes the sftp subsystem and negotiates a version with the server . This method must be the first method called after the channel has been opened . This implementation current supports SFTP protocol version 4 and below .
11,913
public void setCharsetEncoding ( String charset ) throws SshException , UnsupportedEncodingException { if ( version == - 1 ) throw new SshException ( "SFTP Channel must be initialized before setting character set encoding" , SshException . BAD_API_USAGE ) ; String test = "123456890" ; test . getBytes ( charset ) ; CHAR...
Allows the default character encoding to be overriden for filename strings . This method should only be called once the channel has been initialized if the version of the protocol is less than or equal to 3 the encoding is defaulted to latin1 as no encoding is specified by the protocol . If the version is greater than ...
11,914
public SftpMessage sendExtensionMessage ( String request , byte [ ] requestData ) throws SshException , SftpStatusException { try { UnsignedInteger32 id = nextRequestId ( ) ; Packet packet = createPacket ( ) ; packet . write ( SSH_FXP_EXTENDED ) ; packet . writeUINT32 ( id ) ; packet . writeString ( request ) ; sendMes...
Send an extension message and return the response . This is for advanced use only .
11,915
public UnsignedInteger32 postWriteRequest ( byte [ ] handle , long position , byte [ ] data , int off , int len ) throws SftpStatusException , SshException { if ( ( data . length - off ) < len ) { throw new IndexOutOfBoundsException ( "Incorrect data array size!" ) ; } try { UnsignedInteger32 requestId = nextRequestId ...
Send a write request for an open file but do not wait for the response from the server .
11,916
public void writeFile ( byte [ ] handle , UnsignedInteger64 offset , byte [ ] data , int off , int len ) throws SftpStatusException , SshException { getOKRequestStatus ( postWriteRequest ( handle , offset . longValue ( ) , data , off , len ) ) ; }
Write a block of data to an open file .
11,917
public void performSynchronousRead ( byte [ ] handle , int blocksize , OutputStream out , FileTransferProgress progress , long position ) throws SftpStatusException , SshException , TransferCancelledException { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Performing synchronous read postion=" + position + " ...
Perform a synchronous read of a file from the remote file system . This implementation waits for acknowledgement of every data packet before requesting additional data .
11,918
public UnsignedInteger32 postReadRequest ( byte [ ] handle , long offset , int len ) throws SftpStatusException , SshException { try { UnsignedInteger32 requestId = nextRequestId ( ) ; Packet msg = createPacket ( ) ; msg . write ( SSH_FXP_READ ) ; msg . writeInt ( requestId . longValue ( ) ) ; msg . writeBinaryString (...
Post a read request to the server and return the request id ; this is used to optimize file downloads . In normal operation the files are transfered by using a synchronous set of requests however this slows the download as the client has to wait for the servers response before sending another request .
11,919
public int readFile ( byte [ ] handle , UnsignedInteger64 offset , byte [ ] output , int off , int len ) throws SftpStatusException , SshException { try { if ( ( output . length - off ) < len ) { throw new IndexOutOfBoundsException ( "Output array size is smaller than read length!" ) ; } UnsignedInteger32 requestId = n...
Read a block of data from an open file .
11,920
public void createSymbolicLink ( String targetpath , String linkpath ) throws SftpStatusException , SshException { if ( version < 3 ) { throw new SftpStatusException ( SftpStatusException . SSH_FX_OP_UNSUPPORTED , "Symbolic links are not supported by the server SFTP version " + String . valueOf ( version ) ) ; } try { ...
Create a symbolic link .
11,921
public String getSymbolicLinkTarget ( String linkpath ) throws SftpStatusException , SshException { if ( version < 3 ) { throw new SftpStatusException ( SftpStatusException . SSH_FX_OP_UNSUPPORTED , "Symbolic links are not supported by the server SFTP version " + String . valueOf ( version ) ) ; } try { UnsignedInteger...
Get the target path of a symbolic link .
11,922
public String getAbsolutePath ( String path ) throws SftpStatusException , SshException { try { UnsignedInteger32 requestId = nextRequestId ( ) ; Packet msg = createPacket ( ) ; msg . write ( SSH_FXP_REALPATH ) ; msg . writeInt ( requestId . longValue ( ) ) ; msg . writeString ( path , CHARSET_ENCODING ) ; sendMessage ...
Get the absolute path of a file .
11,923
public void recurseMakeDirectory ( String path ) throws SftpStatusException , SshException { SftpFile file ; if ( path . trim ( ) . length ( ) > 0 ) { try { file = openDirectory ( path ) ; file . close ( ) ; } catch ( SshException ioe ) { int idx = 0 ; do { idx = path . indexOf ( '/' , idx ) ; String tmp = ( idx > - 1 ...
Recurse through a hierarchy of directories creating them as necessary .
11,924
public SftpFile openDirectory ( String path ) throws SftpStatusException , SshException { String absolutePath = getAbsolutePath ( path ) ; SftpFileAttributes attrs = getAttributes ( absolutePath ) ; if ( ! attrs . isDirectory ( ) ) { throw new SftpStatusException ( SftpStatusException . SSH_FX_FAILURE , path + " is not...
Open a directory .
11,925
public void closeFile ( SftpFile file ) throws SftpStatusException , SshException { if ( file . getHandle ( ) != null ) { closeHandle ( file . getHandle ( ) ) ; EventServiceImplementation . getInstance ( ) . fireEvent ( ( new Event ( this , J2SSHEventCodes . EVENT_SFTP_FILE_CLOSED , true ) ) . addAttribute ( J2SSHEvent...
Close a file or directory .
11,926
public void removeDirectory ( String path ) throws SftpStatusException , SshException { try { UnsignedInteger32 requestId = nextRequestId ( ) ; Packet msg = createPacket ( ) ; msg . write ( SSH_FXP_RMDIR ) ; msg . writeInt ( requestId . longValue ( ) ) ; msg . writeString ( path , CHARSET_ENCODING ) ; sendMessage ( msg...
Remove an empty directory .
11,927
public void removeFile ( String filename ) throws SftpStatusException , SshException { try { UnsignedInteger32 requestId = nextRequestId ( ) ; Packet msg = createPacket ( ) ; msg . write ( SSH_FXP_REMOVE ) ; msg . writeInt ( requestId . longValue ( ) ) ; msg . writeString ( filename , CHARSET_ENCODING ) ; sendMessage (...
Remove a file .
11,928
public void renameFile ( String oldpath , String newpath ) throws SftpStatusException , SshException { if ( version < 2 ) { throw new SftpStatusException ( SftpStatusException . SSH_FX_OP_UNSUPPORTED , "Renaming files is not supported by the server SFTP version " + String . valueOf ( version ) ) ; } try { UnsignedInteg...
Rename an existing file .
11,929
public SftpFileAttributes getAttributes ( SftpFile file ) throws SftpStatusException , SshException { try { if ( file . getHandle ( ) == null ) { return getAttributes ( file . getAbsolutePath ( ) ) ; } UnsignedInteger32 requestId = nextRequestId ( ) ; Packet msg = createPacket ( ) ; msg . write ( SSH_FXP_FSTAT ) ; msg ...
Get the attributes of a file .
11,930
public void makeDirectory ( String path ) throws SftpStatusException , SshException { makeDirectory ( path , new SftpFileAttributes ( this , SftpFileAttributes . SSH_FILEXFER_TYPE_DIRECTORY ) ) ; }
Make a directory . If the directory exists this method will throw an exception .
11,931
public ServerAuthenticator startSession ( Socket s ) throws IOException { PushbackInputStream in = new PushbackInputStream ( s . getInputStream ( ) ) ; OutputStream out = s . getOutputStream ( ) ; int version = in . read ( ) ; if ( version == 5 ) { if ( ! selectSocks5Authentication ( in , out , 0 ) ) return null ; } el...
Grants access to everyone . Removes authentication related bytes from the stream when a SOCKS5 connection is being made selects an authentication NONE .
11,932
public void start ( ) throws IOException { remote_sock . setSoTimeout ( iddleTimeout ) ; client_sock . setSoTimeout ( iddleTimeout ) ; log ( "Starting UDP relay server on " + relayIP + ":" + relayPort ) ; log ( "Remote socket " + remote_sock . getLocalAddress ( ) + ":" + remote_sock . getLocalPort ( ) ) ; pipe_thread1 ...
Starts udp relay server . Spawns two threads of execution and returns .
11,933
public boolean startSubsystem ( String subsystem ) throws SshException { ByteArrayWriter request = new ByteArrayWriter ( ) ; try { request . writeString ( subsystem ) ; boolean success = sendRequest ( "subsystem" , true , request . toByteArray ( ) ) ; if ( success ) { EventServiceImplementation . getInstance ( ) . fire...
SSH2 supports special subsystems that are identified by a name rather than a command string an example of an SSH2 subsystem is SFTP .
11,934
boolean requestX11Forwarding ( boolean singleconnection , String protocol , String cookie , int screen ) throws SshException { ByteArrayWriter request = new ByteArrayWriter ( ) ; try { request . writeBoolean ( singleconnection ) ; request . writeString ( protocol ) ; request . writeString ( cookie ) ; request . writeIn...
Send a request for X Forwarding .
11,935
public boolean setEnvironmentVariable ( String name , String value ) throws SshException { ByteArrayWriter request = new ByteArrayWriter ( ) ; try { request . writeString ( name ) ; request . writeString ( value ) ; return sendRequest ( "env" , true , request . toByteArray ( ) ) ; } catch ( IOException ex ) { throw new...
The SSH2 session supports the setting of environments variables however in our experiance no server to date allows unconditional setting of variables . This method should be called before the command is started .
11,936
protected void channelRequest ( String requesttype , boolean wantreply , byte [ ] requestdata ) throws SshException { try { if ( requesttype . equals ( "exit-status" ) ) { if ( requestdata != null ) { exitcode = ( int ) ByteArrayReader . readInt ( requestdata , 0 ) ; } } if ( requesttype . equals ( "exit-signal" ) ) { ...
This overidden method handles the exit - status exit - signal and xon - xoff channel requests .
11,937
public void startLocalForwarding ( String addressToBind , int portToBind , String hostToConnect , int portToConnect ) throws SshException { String key = generateKey ( addressToBind , portToBind ) ; SocketListener listener = new SocketListener ( addressToBind , portToBind , hostToConnect , portToConnect ) ; listener . s...
Start s a local listening socket and forwards any connections made to the to the remote side .
11,938
public String [ ] getRemoteForwardings ( ) { String [ ] r = new String [ remoteforwardings . size ( ) - ( remoteforwardings . containsKey ( X11_KEY ) ? 1 : 0 ) ] ; int index = 0 ; for ( Enumeration < String > e = remoteforwardings . keys ( ) ; e . hasMoreElements ( ) ; ) { String key = e . nextElement ( ) ; if ( ! key ...
Returns the currently active remote forwarding listeners .
11,939
public String [ ] getLocalForwardings ( ) { String [ ] r = new String [ socketlisteners . size ( ) ] ; int index = 0 ; for ( Enumeration < String > e = socketlisteners . keys ( ) ; e . hasMoreElements ( ) ; ) { r [ index ++ ] = e . nextElement ( ) ; } return r ; }
Return the currently active local forwarding listeners .
11,940
public ActiveTunnel [ ] getRemoteForwardingTunnels ( ) throws IOException { Vector < ActiveTunnel > v = new Vector < ActiveTunnel > ( ) ; String [ ] remoteForwardings = getRemoteForwardings ( ) ; for ( int i = 0 ; i < remoteForwardings . length ; i ++ ) { ActiveTunnel [ ] tmp = getRemoteForwardingTunnels ( remoteForwar...
Get all the active remote forwarding tunnels
11,941
public ActiveTunnel [ ] getLocalForwardingTunnels ( ) throws IOException { Vector < ActiveTunnel > v = new Vector < ActiveTunnel > ( ) ; String [ ] localForwardings = getLocalForwardings ( ) ; for ( int i = 0 ; i < localForwardings . length ; i ++ ) { ActiveTunnel [ ] tmp = getLocalForwardingTunnels ( localForwardings ...
Get all the active local forwarding tunnels
11,942
public ActiveTunnel [ ] getX11ForwardingTunnels ( ) throws IOException { if ( incomingtunnels . containsKey ( X11_KEY ) ) { Vector < ActiveTunnel > v = incomingtunnels . get ( X11_KEY ) ; ActiveTunnel [ ] t = new ActiveTunnel [ v . size ( ) ] ; v . copyInto ( t ) ; return t ; } return new ActiveTunnel [ ] { } ; }
Get the active X11 forwarding channels .
11,943
public boolean requestRemoteForwarding ( String addressToBind , int portToBind , String hostToConnect , int portToConnect ) throws SshException { if ( ssh . requestRemoteForwarding ( addressToBind , portToBind , hostToConnect , portToConnect , forwardinglistener ) ) { String key = generateKey ( addressToBind , portToBi...
Requests that the remote side start listening for socket connections so that they may be forwarded to to the local destination .
11,944
public void cancelRemoteForwarding ( String bindAddress , int bindPort , boolean killActiveTunnels ) throws SshException { String key = generateKey ( bindAddress , bindPort ) ; boolean killedTunnels = false ; if ( killActiveTunnels ) { try { ActiveTunnel [ ] tunnels = getRemoteForwardingTunnels ( bindAddress , bindPort...
Requests that the remote side stop listening for socket connections . Please note that this feature is not available on SSH1 connections . The only way to stop the server from listening is to disconnect the connection .
11,945
public synchronized void cancelAllRemoteForwarding ( boolean killActiveTunnels ) throws SshException { if ( remoteforwardings == null ) { return ; } for ( Enumeration < String > e = remoteforwardings . keys ( ) ; e . hasMoreElements ( ) ; ) { String host = ( String ) e . nextElement ( ) ; if ( host == null ) return ; t...
Stop all remote forwarding .
11,946
public synchronized void stopAllLocalForwarding ( boolean killActiveTunnels ) throws SshException { for ( Enumeration < String > e = socketlisteners . keys ( ) ; e . hasMoreElements ( ) ; ) { stopLocalForwarding ( ( String ) e . nextElement ( ) , killActiveTunnels ) ; } }
Stop all local forwarding
11,947
public synchronized void stopLocalForwarding ( String bindAddress , int bindPort , boolean killActiveTunnels ) throws SshException { String key = generateKey ( bindAddress , bindPort ) ; stopLocalForwarding ( key , killActiveTunnels ) ; }
Stops a local listening socket from accepting connections .
11,948
public synchronized void stopLocalForwarding ( String key , boolean killActiveTunnels ) throws SshException { if ( key == null ) return ; boolean killedTunnels = false ; if ( killActiveTunnels ) { try { ActiveTunnel [ ] tunnels = getLocalForwardingTunnels ( key ) ; if ( tunnels != null ) { for ( int i = 0 ; i < tunnels...
Stop a local listening socket from accepting connections .
11,949
public boolean verifySignature ( byte [ ] signature , byte [ ] data ) throws SshException { ByteArrayReader bar = new ByteArrayReader ( signature ) ; try { if ( signature . length != 40 && signature . length != 56 && signature . length != 64 ) { byte [ ] sig = bar . readBinaryString ( ) ; String header = new String ( s...
Verify the signature .
11,950
public static ComponentManager getInstance ( ) throws SshException { synchronized ( ComponentManager . class ) { if ( instance == null ) { instance = new JCEComponentManager ( ) ; instance . init ( ) ; } return instance ; } }
Get the installed component manager . Don t want to initialize this at class load time so use a singleton instead . Initialized on the first call to getInstance .
11,951
public void authenticate ( AuthenticationProtocol authentication , String servicename ) throws SshException , AuthenticationResult { try { if ( getUsername ( ) == null || getPassword ( ) == null ) { throw new SshException ( "Username or password not set!" , SshException . BAD_API_USAGE ) ; } if ( passwordChangeRequired...
Implementation of the authentication method .
11,952
public void put ( String localFileRegExp , String remoteFile , boolean recursive , FileTransferProgress progress ) throws SshException , ChannelOpenException { GlobRegExpMatching globMatcher = new GlobRegExpMatching ( ) ; String parentDir ; int fileSeparatorIndex ; parentDir = cwd . getAbsolutePath ( ) ; String relativ...
pattern matches the files in the local directory using local as a glob Regular Expression . For the matching file array put is called to copy the file to the remote directory .
11,953
protected void open ( int remoteid , long remotewindow , int remotepacket ) throws IOException { this . remoteid = remoteid ; this . remotewindow = new DataWindow ( remotewindow , remotepacket ) ; this . state = CHANNEL_OPEN ; synchronized ( listeners ) { for ( Enumeration < ChannelEventListener > e = listeners . eleme...
Called once an SSH_MSG_CHANNEL_OPEN_CONFIRMATION has been sent .
11,954
protected void open ( int remoteid , long remotewindow , int remotepacket , byte [ ] responsedata ) throws IOException { open ( remoteid , remotewindow , remotepacket ) ; }
Once a SSH_MSG_CHANNEL_OPEN_CONFIRMATION message is received the framework calls this method to complete the channel open operation .
11,955
public void close ( ) { boolean performClose = false ; ; synchronized ( this ) { if ( ! closing && state == CHANNEL_OPEN ) { performClose = closing = true ; } } if ( performClose ) { synchronized ( listeners ) { for ( Enumeration < ChannelEventListener > e = listeners . elements ( ) ; e . hasMoreElements ( ) ; ) { ( e ...
Closes the channel . No data may be sent or receieved after this method completes .
11,956
protected void channelRequest ( String requesttype , boolean wantreply , byte [ ] requestdata ) throws SshException { if ( wantreply ) { ByteArrayWriter msg = new ByteArrayWriter ( ) ; try { msg . write ( ( byte ) SSH_MSG_CHANNEL_FAILURE ) ; msg . writeInt ( remoteid ) ; connection . sendMessage ( msg . toByteArray ( )...
Called when a channel request is received by default this method sends a failure message if the remote side requests a reply . Overidden methods should ALWAYS call this superclass method .
11,957
public void setPreferredCipherCS ( String name ) throws SshException { if ( name == null ) return ; if ( ciphersCS . contains ( name ) ) { prefCipherCS = name ; setCipherPreferredPositionCS ( name , 0 ) ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ; } }
Set the preferred cipher for the Client - > Server stream .
11,958
public void setPreferredCipherSC ( String name ) throws SshException { if ( name == null ) return ; if ( ciphersSC . contains ( name ) ) { prefCipherSC = name ; setCipherPreferredPositionSC ( name , 0 ) ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ; } }
Set the preferred cipher for the Server - > Client stream .
11,959
public void setPreferredMacCS ( String name ) throws SshException { if ( name == null ) return ; if ( macCS . contains ( name ) ) { prefMacCS = name ; setMacPreferredPositionCS ( name , 0 ) ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ; } }
Set the preferred mac for the Client - > Server stream .
11,960
public void setPreferredMacSC ( String name ) throws SshException { if ( name == null ) return ; if ( macSC . contains ( name ) ) { prefMacSC = name ; setMacPreferredPositionSC ( name , 0 ) ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ; } }
Set the preferred mac for the Server - > Client stream .
11,961
public void setPreferredCompressionCS ( String name ) throws SshException { if ( name == null ) return ; if ( compressionsCS . contains ( name ) ) { prefCompressionCS = name ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ; } }
Set the preferred compression for the Client - > Server stream .
11,962
public void setPreferredCompressionSC ( String name ) throws SshException { if ( name == null ) return ; if ( compressionsSC . contains ( name ) ) { prefCompressionSC = name ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ; } }
Set the preferred compression for the Server - > Client stream .
11,963
public void setPreferredKeyExchange ( String name ) throws SshException { if ( name == null ) return ; if ( keyExchanges . contains ( name ) ) { prefKeyExchange = name ; setKeyExchangePreferredPosition ( name , 0 ) ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ;...
Set the preferred key exchange method .
11,964
public void setPreferredPublicKey ( String name ) throws SshException { if ( name == null ) return ; if ( publicKeys . contains ( name ) ) { prefPublicKey = name ; setPublicKeyPreferredPosition ( name , 0 ) ; } else { throw new SshException ( name + " is not supported" , SshException . UNSUPPORTED_ALGORITHM ) ; } }
Set the preferred public key algorithm .
11,965
public void close ( ) throws IOException { try { file . close ( ) ; UnsignedInteger32 requestid ; while ( outstandingRequests . size ( ) > 0 ) { requestid = ( UnsignedInteger32 ) outstandingRequests . elementAt ( 0 ) ; outstandingRequests . removeElementAt ( 0 ) ; sftp . getResponse ( requestid ) ; } } catch ( SshExcep...
Closes the SFTP file handle .
11,966
public static void debug ( Object source , String message , Throwable t ) { LoggerFactory . getInstance ( ) . log ( LoggerLevel . DEBUG , source , message , t ) ; }
An error log event
11,967
public static void debug ( Object source , String message ) { LoggerFactory . getInstance ( ) . log ( LoggerLevel . INFO , source , message ) ; }
A debug event
11,968
public static void error ( Object source , String message , Throwable t ) { LoggerFactory . getInstance ( ) . log ( LoggerLevel . ERROR , source , message , t ) ; }
An exception event
11,969
private void formRequest ( ) { byte [ ] user_bytes = userName . getBytes ( ) ; byte [ ] password_bytes = password . getBytes ( ) ; request = new byte [ 3 + user_bytes . length + password_bytes . length ] ; request [ 0 ] = ( byte ) 1 ; request [ 1 ] = ( byte ) user_bytes . length ; System . arraycopy ( user_bytes , 0 , ...
Convert UserName password in to binary form ready to be send to server
11,970
public void startTransportProtocol ( SshTransport provider , Ssh2Context context , String localIdentification , String remoteIdentification , Ssh2Client client ) throws SshException { try { this . transportIn = new DataInputStream ( provider . getInputStream ( ) ) ; this . transportOut = provider . getOutputStream ( ) ...
Starts the protocol on the provider .
11,971
public void disconnect ( int reason , String disconnectReason ) { ByteArrayWriter baw = new ByteArrayWriter ( ) ; try { this . disconnectReason = disconnectReason ; baw . write ( SSH_MSG_DISCONNECT ) ; baw . writeInt ( reason ) ; baw . writeString ( disconnectReason ) ; baw . writeString ( "" ) ; Log . info ( this , "S...
Disconnect from the remote host . No more messages can be sent after this method has been called .
11,972
public byte [ ] nextMessage ( ) throws SshException { if ( Log . isDebugEnabled ( ) ) { if ( verbose ) { Log . debug ( this , "transport next message" ) ; } } synchronized ( transportIn ) { byte [ ] msg ; do { msg = readMessage ( ) ; } while ( processMessage ( msg ) ) ; return msg ; } }
Get the next message . The message returned will be the full message data so skipping the first 5 bytes is required before the message data can be read .
11,973
public void startService ( String servicename ) throws SshException { ByteArrayWriter baw = new ByteArrayWriter ( ) ; try { baw . write ( SSH_MSG_SERVICE_REQUEST ) ; baw . writeString ( servicename ) ; if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Sending SSH_MSG_SERVICE_REQUEST" ) ; } sendMessage ( baw . toB...
Request that the remote server starts a transport protocol service . This is only available in CLIENT_MODE .
11,974
public boolean processMessage ( byte [ ] msg ) throws SshException { try { if ( msg . length < 1 ) { disconnect ( TransportProtocol . PROTOCOL_ERROR , "Invalid message received" ) ; throw new SshException ( "Invalid transport protocol message" , SshException . INTERNAL_ERROR ) ; } switch ( msg [ 0 ] ) { case SSH_MSG_DI...
Process a message . This should be called when reading messages from outside of the transport protocol so that the transport protocol can parse its own messages .
11,975
public static String getFingerprint ( byte [ ] encoded , String algorithm ) throws SshException { Digest md5 = ( Digest ) ComponentManager . getInstance ( ) . supportedDigests ( ) . getInstance ( algorithm ) ; md5 . putBytes ( encoded ) ; byte [ ] digest = md5 . doFinal ( ) ; StringBuffer buf = new StringBuffer ( ) ; i...
Generate an SSH key fingerprint with a specific algorithm .
11,976
public boolean canWrite ( ) throws SftpStatusException , SshException { if ( ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IWUSR ) == SftpFileAttributes . S_IWUSR || ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IWGRP ) == SftpFileAttributes . S_IW...
Determine whether the user has write access to the file . This checks the S_IWUSR flag is set in permissions .
11,977
public boolean canRead ( ) throws SftpStatusException , SshException { if ( ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IRUSR ) == SftpFileAttributes . S_IRUSR || ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IRGRP ) == SftpFileAttributes . S_IRG...
Determine whether the user has read access to the file . This checks the S_IRUSR flag is set in permissions .
11,978
public SftpFileAttributes getAttributes ( ) throws SftpStatusException , SshException { if ( attrs == null ) { attrs = sftp . getAttributes ( getAbsolutePath ( ) ) ; } return attrs ; }
Get the files attributes .
11,979
public boolean isFifo ( ) throws SftpStatusException , SshException { if ( ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IFIFO ) == SftpFileAttributes . S_IFIFO ) return true ; return false ; }
Determine whether the file is pointing to a pipe .
11,980
public boolean isBlock ( ) throws SftpStatusException , SshException { if ( ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IFBLK ) == SftpFileAttributes . S_IFBLK ) { return true ; } return false ; }
Determine whether the file is pointing to a block special file .
11,981
public boolean isCharacter ( ) throws SftpStatusException , SshException { if ( ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IFCHR ) == SftpFileAttributes . S_IFCHR ) { return true ; } return false ; }
Determine whether the file is pointing to a character mode device .
11,982
public boolean isSocket ( ) throws SftpStatusException , SshException { if ( ( getAttributes ( ) . getPermissions ( ) . longValue ( ) & SftpFileAttributes . S_IFSOCK ) == SftpFileAttributes . S_IFSOCK ) { return true ; } return false ; }
Determine whether the file is pointing to a socket .
11,983
protected synchronized void write ( int b ) throws IOException { if ( closed ) { throw new IOException ( "The buffer is closed" ) ; } verifyBufferSize ( 1 ) ; buf [ writepos ] = ( byte ) b ; writepos ++ ; notifyAll ( ) ; }
Write a byte array to the buffer
11,984
protected synchronized int read ( ) throws IOException { try { block ( ) ; } catch ( InterruptedException ex ) { throw new InterruptedIOException ( "The blocking operation was interrupted" ) ; } if ( closed && available ( ) <= 0 ) { return - 1 ; } return buf [ readpos ++ ] ; }
Read a byte from the buffer
11,985
protected synchronized int read ( byte [ ] data , int offset , int len ) throws IOException { try { block ( ) ; } catch ( InterruptedException ex ) { throw new InterruptedIOException ( "The blocking operation was interrupted" ) ; } if ( closed && available ( ) <= 0 ) { return - 1 ; } int read = ( len > ( writepos - rea...
Read a byte array from the buffer
11,986
public synchronized void add ( String name , Class < ? > cls ) { if ( locked ) { throw new IllegalStateException ( "Component factory is locked. Components cannot be added" ) ; } supported . put ( name , cls ) ; if ( ! order . contains ( name ) ) order . addElement ( name ) ; }
Add a new component type to the factory . This method throws an exception if the class cannot be resolved . The name of the component IS NOT verified to allow component implementations to be overridden .
11,987
public Object getInstance ( String name ) throws SshException { if ( supported . containsKey ( name ) ) { try { return createInstance ( name , ( Class < ? > ) supported . get ( name ) ) ; } catch ( Throwable t ) { throw new SshException ( t . getMessage ( ) , SshException . INTERNAL_ERROR ) ; } } throw new SshException...
Get a new instance of a supported component .
11,988
private synchronized String createDelimitedList ( String preferred ) { StringBuffer listBuf = new StringBuffer ( ) ; int prefIndex = order . indexOf ( preferred ) ; if ( prefIndex != - 1 ) { listBuf . append ( preferred ) ; } for ( int i = 0 ; i < order . size ( ) ; i ++ ) { if ( prefIndex == i ) { continue ; } listBuf...
Create a delimited list of supported components .
11,989
public Socket accept ( ) throws IOException { Socket s ; if ( ! doing_direct ) { if ( proxy == null ) return null ; ProxyMessage msg = proxy . accept ( ) ; s = msg . ip == null ? new SocksSocket ( msg . host , msg . port , proxy ) : new SocksSocket ( msg . ip , msg . port , proxy ) ; proxy . proxySocket . setSoTimeout ...
Accepts the incoming connection .
11,990
public InetAddress getInetAddress ( ) { if ( localIP == null ) { try { localIP = InetAddress . getByName ( localHost ) ; } catch ( UnknownHostException e ) { return null ; } } return localIP ; }
Get address assigned by proxy to listen for incomming connections or the local machine address if doing direct connection .
11,991
public void setSoTimeout ( int timeout ) throws SocketException { super . setSoTimeout ( timeout ) ; if ( ! doing_direct ) proxy . proxySocket . setSoTimeout ( timeout ) ; }
Set Timeout .
11,992
public static String getStatusText ( int status ) { switch ( status ) { case SSH_FX_OK : return "OK" ; case SSH_FX_EOF : return "EOF" ; case SSH_FX_NO_SUCH_FILE : return "No such file." ; case SSH_FX_PERMISSION_DENIED : return "Permission denied." ; case SSH_FX_FAILURE : return "Server responded with an unknown failure...
Convert a SSH_FXP_STATUS code into a readable string
11,993
public static SshPublicKeyFile parse ( byte [ ] formattedkey ) throws IOException { try { try { return new OpenSSHPublicKeyFile ( formattedkey ) ; } catch ( IOException ex ) { try { return new SECSHPublicKeyFile ( formattedkey ) ; } catch ( IOException ex2 ) { throw new IOException ( "Unable to parse key, format could ...
Parse a formatted public key and return a file representation .
11,994
public static BigInteger getSafePrime ( UnsignedInteger32 maximumSize ) { BigInteger prime = group1 ; for ( Iterator < BigInteger > it = safePrimes . iterator ( ) ; it . hasNext ( ) ; ) { BigInteger p = it . next ( ) ; int len = p . bitLength ( ) ; if ( len > maximumSize . intValue ( ) ) { break ; } prime = p ; } retur...
get the biggest safe prime from the list that is < = maximumSize
11,995
public void read ( InputStream in , boolean clientMode ) throws SocksException , IOException { data = null ; ip = null ; DataInputStream di = new DataInputStream ( in ) ; version = di . readUnsignedByte ( ) ; command = di . readUnsignedByte ( ) ; if ( clientMode && command != 0 ) throw new SocksException ( command ) ; ...
Initialises Message from the stream . Reads server response or client request from given stream .
11,996
public void write ( OutputStream out ) throws SocksException , IOException { if ( data == null ) { Socks5Message msg ; if ( addrType == SOCKS_ATYP_DOMAINNAME ) msg = new Socks5Message ( command , host , port ) ; else { if ( ip == null ) { try { ip = InetAddress . getByName ( host ) ; } catch ( UnknownHostException uh_e...
Writes the message to the stream .
11,997
public InetAddress getInetAddress ( ) throws UnknownHostException { if ( ip != null ) return ip ; return ( ip = InetAddress . getByName ( host ) ) ; }
Returns IP field of the message as IP if the message was created with ATYP of HOSTNAME it will attempt to resolve the hostname which might fail .
11,998
public void run ( ) { if ( ! initProxy ( ) ) { if ( mode != OK_MODE ) return ; if ( net_thread != Thread . currentThread ( ) ) return ; mode = COMMAND_MODE ; warning_label . setText ( "Look up failed." ) ; warning_label . invalidate ( ) ; return ; } while ( ! warning_dialog . isShowing ( ) ) ; ; warning_dialog . dispos...
Resolves proxy address in other thread to avoid annoying blocking in GUI thread .
11,999
public void cdup ( ) throws SftpStatusException , SshException { SftpFile cd = sftp . getFile ( cwd ) ; SftpFile parent = cd . getParent ( ) ; if ( parent != null ) cwd = parent . getAbsolutePath ( ) ; }
Change the working directory to the parent directory