mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 15:20:54 +03:00
@@ -212,7 +212,7 @@ public class SSHClient
|
|||||||
public void auth(String username, Iterable<AuthMethod> methods)
|
public void auth(String username, Iterable<AuthMethod> methods)
|
||||||
throws UserAuthException, TransportException {
|
throws UserAuthException, TransportException {
|
||||||
checkConnected();
|
checkConnected();
|
||||||
final Deque<UserAuthException> savedEx = new LinkedList<>();
|
final Deque<UserAuthException> savedEx = new LinkedList<UserAuthException>();
|
||||||
for (AuthMethod method: methods) {
|
for (AuthMethod method: methods) {
|
||||||
method.setLoggerFactory(loggerFactory);
|
method.setLoggerFactory(loggerFactory);
|
||||||
try {
|
try {
|
||||||
@@ -334,7 +334,7 @@ public class SSHClient
|
|||||||
*/
|
*/
|
||||||
public void authPublickey(String username, Iterable<KeyProvider> keyProviders)
|
public void authPublickey(String username, Iterable<KeyProvider> keyProviders)
|
||||||
throws UserAuthException, TransportException {
|
throws UserAuthException, TransportException {
|
||||||
final List<AuthMethod> am = new LinkedList<>();
|
final List<AuthMethod> am = new LinkedList<AuthMethod>();
|
||||||
for (KeyProvider kp : keyProviders)
|
for (KeyProvider kp : keyProviders)
|
||||||
am.add(new AuthPublickey(kp));
|
am.add(new AuthPublickey(kp));
|
||||||
auth(username, am);
|
auth(username, am);
|
||||||
@@ -377,7 +377,7 @@ public class SSHClient
|
|||||||
*/
|
*/
|
||||||
public void authPublickey(String username, String... locations)
|
public void authPublickey(String username, String... locations)
|
||||||
throws UserAuthException, TransportException {
|
throws UserAuthException, TransportException {
|
||||||
final List<KeyProvider> keyProviders = new LinkedList<>();
|
final List<KeyProvider> keyProviders = new LinkedList<KeyProvider>();
|
||||||
for (String loc : locations) {
|
for (String loc : locations) {
|
||||||
try {
|
try {
|
||||||
log.debug("Attempting to load key from: {}", loc);
|
log.debug("Attempting to load key from: {}", loc);
|
||||||
@@ -407,7 +407,7 @@ public class SSHClient
|
|||||||
public void authGssApiWithMic(String username, LoginContext context, Oid supportedOid, Oid... supportedOids)
|
public void authGssApiWithMic(String username, LoginContext context, Oid supportedOid, Oid... supportedOids)
|
||||||
throws UserAuthException, TransportException {
|
throws UserAuthException, TransportException {
|
||||||
// insert supportedOid to the front of the list since ordering matters
|
// insert supportedOid to the front of the list since ordering matters
|
||||||
List<Oid> oids = new ArrayList<>(Arrays.asList(supportedOids));
|
List<Oid> oids = new ArrayList<Oid>(Arrays.asList(supportedOids));
|
||||||
oids.add(0, supportedOid);
|
oids.add(0, supportedOid);
|
||||||
|
|
||||||
auth(username, new AuthGssApiWithMic(context, oids));
|
auth(username, new AuthGssApiWithMic(context, oids));
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ public abstract class AbstractChannel
|
|||||||
/** Remote recipient ID */
|
/** Remote recipient ID */
|
||||||
private int recipient;
|
private int recipient;
|
||||||
|
|
||||||
|
private boolean eof = false;
|
||||||
|
|
||||||
private final Queue<Event<ConnectionException>> chanReqResponseEvents = new LinkedList<Event<ConnectionException>>();
|
private final Queue<Event<ConnectionException>> chanReqResponseEvents = new LinkedList<Event<ConnectionException>>();
|
||||||
|
|
||||||
/* The lock used by to create the open & close events */
|
/* The lock used by to create the open & close events */
|
||||||
@@ -191,9 +193,14 @@ public abstract class AbstractChannel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEOF() {
|
||||||
|
return eof;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoggerFactory getLoggerFactory() {
|
public LoggerFactory getLoggerFactory() {
|
||||||
return loggerFactory;
|
return loggerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void gotClose()
|
private void gotClose()
|
||||||
@@ -394,6 +401,7 @@ public abstract class AbstractChannel
|
|||||||
/** Called when EOF has been received. Subclasses can override but must call super. */
|
/** Called when EOF has been received. Subclasses can override but must call super. */
|
||||||
protected void eofInputStreams() {
|
protected void eofInputStreams() {
|
||||||
in.eof();
|
in.eof();
|
||||||
|
eof = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -156,6 +156,11 @@ public interface Channel extends Closeable, SSHPacketHandler, ErrorNotifiable {
|
|||||||
|
|
||||||
void join(long timeout, TimeUnit unit) throws ConnectionException;
|
void join(long timeout, TimeUnit unit) throws ConnectionException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether EOF has been received.
|
||||||
|
*/
|
||||||
|
boolean isEOF();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the LoggerFactory associated with the SSH client.
|
* Get the LoggerFactory associated with the SSH client.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class FileMode {
|
|||||||
/** directory */
|
/** directory */
|
||||||
DIRECTORY(0040000),
|
DIRECTORY(0040000),
|
||||||
/** symbolic link */
|
/** symbolic link */
|
||||||
SYMKLINK(0120000),
|
SYMLINK(0120000),
|
||||||
/** unknown */
|
/** unknown */
|
||||||
UNKNOWN(0);
|
UNKNOWN(0);
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,30 @@ public final class Response
|
|||||||
BAD_MESSAGE(5),
|
BAD_MESSAGE(5),
|
||||||
NO_CONNECTION(6),
|
NO_CONNECTION(6),
|
||||||
CONNECITON_LOST(7),
|
CONNECITON_LOST(7),
|
||||||
OP_UNSUPPORTED(8);
|
OP_UNSUPPORTED(8),
|
||||||
|
INVALID_HANDLE(9),
|
||||||
|
NO_SUCH_PATH(10),
|
||||||
|
FILE_ALREADY_EXISTS(11),
|
||||||
|
WRITE_PROTECT(12),
|
||||||
|
NO_MEDIA(13),
|
||||||
|
NO_SPACE_ON_FILESYSTEM(14),
|
||||||
|
QUOTA_EXCEEDED(15),
|
||||||
|
UNKNOWN_PRINCIPAL(16),
|
||||||
|
LOCK_CONFLICT(17),
|
||||||
|
DIR_NOT_EMPTY(18),
|
||||||
|
NOT_A_DIRECTORY(19),
|
||||||
|
INVALID_FILENAME(20),
|
||||||
|
LINK_LOOP(21),
|
||||||
|
CANNOT_DELETE(22),
|
||||||
|
INVALID_PARAMETER(23),
|
||||||
|
FILE_IS_A_DIRECTORY(24),
|
||||||
|
BYTE_RANGE_LOCK_CONFLICT(25),
|
||||||
|
BYTE_RANGE_LOCK_REFUSED(26),
|
||||||
|
DELETE_PENDING(27),
|
||||||
|
FILE_CORRUPT(28),
|
||||||
|
OWNER_INVALID(29),
|
||||||
|
GROUP_INVALID(30),
|
||||||
|
NO_MATCHING_BYTE_RANGE_LOCK(31);
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class SFTPClient
|
|||||||
|
|
||||||
public void mkdirs(String path)
|
public void mkdirs(String path)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final Deque<String> dirsToMake = new LinkedList<>();
|
final Deque<String> dirsToMake = new LinkedList<String>();
|
||||||
for (PathComponents current = engine.getPathHelper().getComponents(path); ;
|
for (PathComponents current = engine.getPathHelper().getComponents(path); ;
|
||||||
current = engine.getPathHelper().getComponents(current.getParent())) {
|
current = engine.getPathHelper().getComponents(current.getParent())) {
|
||||||
final FileAttributes attrs = statExistence(current.getPath());
|
final FileAttributes attrs = statExistence(current.getPath());
|
||||||
|
|||||||
@@ -229,14 +229,36 @@ public class SFTPFileTransfer
|
|||||||
final String remote)
|
final String remote)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final String adjusted = prepareFile(local, remote);
|
final String adjusted = prepareFile(local, remote);
|
||||||
try (RemoteFile rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC))) {
|
RemoteFile rf = null;
|
||||||
try (InputStream fis = local.getInputStream();
|
InputStream fis = null;
|
||||||
RemoteFile.RemoteFileOutputStream rfos = rf.new RemoteFileOutputStream(0, 16)) {
|
RemoteFile.RemoteFileOutputStream rfos = null;
|
||||||
new StreamCopier(fis, rfos, engine.getLoggerFactory())
|
try {
|
||||||
.bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead())
|
rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC));
|
||||||
.keepFlushing(false)
|
fis = local.getInputStream();
|
||||||
.listener(listener)
|
rfos = rf.new RemoteFileOutputStream(0, 16);
|
||||||
.copy();
|
new StreamCopier(fis, rfos, engine.getLoggerFactory())
|
||||||
|
.bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead())
|
||||||
|
.keepFlushing(false)
|
||||||
|
.listener(listener)
|
||||||
|
.copy();
|
||||||
|
} finally {
|
||||||
|
if (rf != null) {
|
||||||
|
try {
|
||||||
|
rf.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fis != null) {
|
||||||
|
try {
|
||||||
|
fis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rfos != null) {
|
||||||
|
try {
|
||||||
|
rfos.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return adjusted;
|
return adjusted;
|
||||||
|
|||||||
Reference in New Issue
Block a user