Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility features #269

Merged
merged 6 commits into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/net/schmizz/sshj/SSHClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void auth(String username, AuthMethod... methods)
public void auth(String username, Iterable<AuthMethod> methods)
throws UserAuthException, TransportException {
checkConnected();
final Deque<UserAuthException> savedEx = new LinkedList<>();
final Deque<UserAuthException> savedEx = new LinkedList<UserAuthException>();
for (AuthMethod method: methods) {
method.setLoggerFactory(loggerFactory);
try {
Expand Down Expand Up @@ -334,7 +334,7 @@ public void authPublickey(String username)
*/
public void authPublickey(String username, Iterable<KeyProvider> keyProviders)
throws UserAuthException, TransportException {
final List<AuthMethod> am = new LinkedList<>();
final List<AuthMethod> am = new LinkedList<AuthMethod>();
for (KeyProvider kp : keyProviders)
am.add(new AuthPublickey(kp));
auth(username, am);
Expand Down Expand Up @@ -377,7 +377,7 @@ public void authPublickey(String username, KeyProvider... keyProviders)
*/
public void authPublickey(String username, String... locations)
throws UserAuthException, TransportException {
final List<KeyProvider> keyProviders = new LinkedList<>();
final List<KeyProvider> keyProviders = new LinkedList<KeyProvider>();
for (String loc : locations) {
try {
log.debug("Attempting to load key from: {}", loc);
Expand Down Expand Up @@ -407,7 +407,7 @@ public void authPublickey(String username, String... locations)
public void authGssApiWithMic(String username, LoginContext context, Oid supportedOid, Oid... supportedOids)
throws UserAuthException, TransportException {
// 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);

auth(username, new AuthGssApiWithMic(context, oids));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public abstract class AbstractChannel
/** Remote recipient ID */
private int recipient;

private boolean eof = false;

private final Queue<Event<ConnectionException>> chanReqResponseEvents = new LinkedList<Event<ConnectionException>>();

/* The lock used by to create the open & close events */
Expand Down Expand Up @@ -191,9 +193,14 @@ public void handle(Message msg, SSHPacket buf)
}
}

@Override
public boolean isEOF() {
return eof;
}

@Override
public LoggerFactory getLoggerFactory() {
return loggerFactory;
return loggerFactory;
}

private void gotClose()
Expand Down Expand Up @@ -394,6 +401,7 @@ private void gotEOF()
/** Called when EOF has been received. Subclasses can override but must call super. */
protected void eofInputStreams() {
in.eof();
eof = true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ interface Forwarded extends Channel {

void join(long timeout, TimeUnit unit) throws ConnectionException;

/**
* Returns whether EOF has been received.
*/
boolean isEOF();

/**
* Get the LoggerFactory associated with the SSH client.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/schmizz/sshj/sftp/FileMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static enum Type {
/** directory */
DIRECTORY(0040000),
/** symbolic link */
SYMKLINK(0120000),
SYMLINK(0120000),
/** unknown */
UNKNOWN(0);

Expand Down
25 changes: 24 additions & 1 deletion src/main/java/net/schmizz/sshj/sftp/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,30 @@ public static enum StatusCode {
BAD_MESSAGE(5),
NO_CONNECTION(6),
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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/schmizz/sshj/sftp/SFTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void mkdir(String dirname)

public void mkdirs(String path)
throws IOException {
final Deque<String> dirsToMake = new LinkedList<>();
final Deque<String> dirsToMake = new LinkedList<String>();
for (PathComponents current = engine.getPathHelper().getComponents(path); ;
current = engine.getPathHelper().getComponents(current.getParent())) {
final FileAttributes attrs = statExistence(current.getPath());
Expand Down
38 changes: 30 additions & 8 deletions src/main/java/net/schmizz/sshj/sftp/SFTPFileTransfer.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,36 @@ private String uploadFile(final StreamCopier.Listener listener,
final String remote)
throws IOException {
final String adjusted = prepareFile(local, remote);
try (RemoteFile rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC))) {
try (InputStream fis = local.getInputStream();
RemoteFile.RemoteFileOutputStream rfos = rf.new RemoteFileOutputStream(0, 16)) {
new StreamCopier(fis, rfos, engine.getLoggerFactory())
.bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead())
.keepFlushing(false)
.listener(listener)
.copy();
RemoteFile rf = null;
InputStream fis = null;
RemoteFile.RemoteFileOutputStream rfos = null;
try {
rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE, OpenMode.CREAT, OpenMode.TRUNC));
fis = local.getInputStream();
rfos = rf.new RemoteFileOutputStream(0, 16);
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;
Expand Down