public synchronized void close() throws IOException { if (closed) { return; } super.close(); closed = true; if (!channel.isConnected()) { throw new IOException(E_CLIENT_NOTCONNECTED); } try { Session session = channel.getSession(); channel.disconnect(); session.disconnect(); } catch (JSchException e) { throw new IOException(StringUtils.stringifyException(e)); } } }
void disconnect(ChannelSftp channel) throws IOException { if (channel != null) { // close connection if too many active connections boolean closeConnection = false; synchronized (this) { if (liveConnectionCount > maxConnection) { --liveConnectionCount; con2infoMap.remove(channel); closeConnection = true; } } if (closeConnection) { if (channel.isConnected()) { try { Session session = channel.getSession(); channel.disconnect(); session.disconnect(); } catch (JSchException e) { throw new IOException(StringUtils.stringifyException(e)); } } } else { returnToPool(channel); } } }
@Override public void close() throws Exception { sftp.getSession().disconnect(); sftp.disconnect(); }
private void disconnectQuietly() { channel.disconnect(); try { channel.getSession().disconnect(); } catch (@SuppressWarnings("unused") JSchException e) { // ignore } }
private void closeChannel() { if (channel != null) { channel.disconnect(); try { channel.getSession().disconnect(); } catch (JSchException ex) { // Ignore possible exception thrown by getSession() } } channel = null; }
private void disconnect() throws IOException { channel.disconnect(); try { channel.getSession().disconnect(); } catch (JSchException e) { throw asIOException(e); } }
private void keepAlive() throws IOException { try { channel.getSession().sendKeepAliveMsg(); } catch (Exception e) { // can't be less generic as sendKeepAliveMsg declares to throw Exception throw asIOException(e); } }
private boolean isConnected() { if (channel.isConnected()) { try { channel.getSession().sendKeepAliveMsg(); return true; } catch (@SuppressWarnings("unused") Exception e) { // the keep alive failed - treat as not connected, and actually disconnect quietly disconnectQuietly(); } } return false; }
private void sendINIT() throws Exception{ packet.reset(); putHEAD(SSH_FXP_INIT, 5); buf.putInt(3); // version 3 getSession().write(packet, this, 5+4); }
private void sendINIT() throws Exception{ packet.reset(); putHEAD(SSH_FXP_INIT, 5); buf.putInt(3); // version 3 getSession().write(packet, this, 5+4); }
private void sendPacketPath(byte fxp, byte[] path) throws Exception{ packet.reset(); putHEAD(fxp, 9+path.length); buf.putInt(seq++); buf.putString(path); // path getSession().write(packet, this, 9+path.length+4); } private void sendPacketPath(byte fxp, byte[] p1, byte[] p2) throws Exception{
private void sendOPEN(byte[] path, int mode) throws Exception{ packet.reset(); putHEAD(SSH_FXP_OPEN, 17+path.length); buf.putInt(seq++); buf.putString(path); buf.putInt(mode); buf.putInt(0); // attrs getSession().write(packet, this, 17+path.length+4); } private void sendPacketPath(byte fxp, byte[] path) throws Exception{
private void sendREAD(byte[] handle, long offset, int length) throws Exception{ packet.reset(); putHEAD(SSH_FXP_READ, 21+handle.length); buf.putInt(seq++); buf.putString(handle); buf.putLong(offset); buf.putInt(length); getSession().write(packet, this, 21+handle.length+4); }
private void sendSETSTAT(byte[] path, SftpATTRS attr) throws Exception{ packet.reset(); putHEAD(SSH_FXP_SETSTAT, 9+path.length+attr.length()); buf.putInt(seq++); buf.putString(path); // path attr.dump(buf); getSession().write(packet, this, 9+path.length+attr.length()+4); } private void sendREMOVE(byte[] path) throws Exception{
private void sendSETSTAT(byte[] path, SftpATTRS attr) throws Exception { packet.reset(); putHEAD(SSH_FXP_SETSTAT, 9 + path.length + attr.length()); buf.putInt(seq++); buf.putString(path); attr.dump(buf); getSession().write(packet, this, 9 + path.length + attr.length() + 4); }
private void sendSETSTAT(byte[] path, SftpATTRS attr) throws Exception{ packet.reset(); putHEAD(SSH_FXP_SETSTAT, 9+path.length+attr.length()); buf.putInt(seq++); buf.putString(path); // path attr.dump(buf); getSession().write(packet, this, 9+path.length+attr.length()+4); } private void sendREMOVE(byte[] path) throws Exception{
private void sendMKDIR(byte[] path, SftpATTRS attr) throws Exception{ packet.reset(); putHEAD(SSH_FXP_MKDIR, 9+path.length+(attr!=null?attr.length():4)); buf.putInt(seq++); buf.putString(path); // path if(attr!=null) attr.dump(buf); else buf.putInt(0); getSession().write(packet, this, 9+path.length+(attr!=null?attr.length():4)+4); } private void sendRMDIR(byte[] path) throws Exception{
private void sendMKDIR(byte[] path, SftpATTRS attr) throws Exception{ packet.reset(); putHEAD(SSH_FXP_MKDIR, 9+path.length+(attr!=null?attr.length():4)); buf.putInt(seq++); buf.putString(path); // path if(attr!=null) attr.dump(buf); else buf.putInt(0); getSession().write(packet, this, 9+path.length+(attr!=null?attr.length():4)+4); } private void sendRMDIR(byte[] path) throws Exception{
private void sendMKDIR(byte[] path, SftpATTRS attr) throws Exception{ packet.reset(); putHEAD(SSH_FXP_MKDIR, 9+path.length+(attr!=null?attr.length():4)); buf.putInt(seq++); buf.putString(path); // path if(attr!=null) attr.dump(buf); else buf.putInt(0); getSession().write(packet, this, 9+path.length+(attr!=null?attr.length():4)+4); } private void sendRMDIR(byte[] path) throws Exception{
private void sendMKDIR(byte[] path, SftpATTRS attr) throws Exception { packet.reset(); putHEAD(SSH_FXP_MKDIR, 9 + path.length + (attr != null ? attr.length() : 4)); buf.putInt(seq++); buf.putString(path); if (attr != null) attr.dump(buf); else buf.putInt(0); getSession().write(packet, this, 9 + path.length + (attr != null ? attr.length() : 4) + 4); }