Compare commits

..

12 Commits

Author SHA1 Message Date
Shikhar Bhushan
20c5ab8dfc [maven-release-plugin] prepare release v0.3.1 2011-03-02 20:44:25 +00:00
Incendium
d9c438ed16 Fixed issue with StatefulSFTPClient.put not transferring files. 2011-03-01 14:53:12 -08:00
Shikhar Bhushan
653e8ad4f2 In SCP, warning means error... 2011-02-27 20:48:26 +00:00
Shikhar Bhushan
c46dc913e8 A Config suitable for running with Android 2.3+ 2011-02-12 23:25:32 +00:00
Shikhar Bhushan
069ebbd47d Try and be helpful on SessionChannel reuse with a more explicit error condition 2011-02-12 20:25:26 +00:00
Shikhar Bhushan
da2cec8fa2 Add a timed join() method to Channel, update Exec example 2011-02-12 20:23:58 +00:00
Shikhar Bhushan
75caa8bcf3 Need to fix my intellij setup on linux... 2010-12-30 22:48:09 +00:00
Shikhar Bhushan
f664b7b24f Merge branch 'master' of github.com:shikhar/sshj 2010-12-30 22:43:34 +00:00
shikhar
70f3aeee68 SessionChannel should override notifyError() in order to notify the stderr stream 2010-12-30 22:43:00 +00:00
shikhar
882d40a1b6 SessionChannel should override notifyError() in order to notify the stderr stream 2010-12-30 22:38:02 +00:00
Shikhar Bhushan
9649b2f72e lets try this flattr thing 2010-08-22 00:09:04 +01:00
Shikhar Bhushan
79a8d0b3ad [maven-release-plugin] prepare for next development iteration 2010-08-15 19:39:01 +01:00
10 changed files with 73 additions and 33 deletions

View File

@@ -1,3 +1,8 @@
.. image:: http://api.flattr.com/button/button-compact-static-100x17.png
:align: right
:alt: Flattr this
:target: http://flattr.com/thing/49085/sshj-ssh-scp-and-sftp-library-for-java
sshj - SSHv2 library for Java
==============================

View File

@@ -6,7 +6,7 @@
<groupId>net.schmizz</groupId>
<artifactId>sshj</artifactId>
<packaging>jar</packaging>
<version>0.3.0</version>
<version>0.3.1</version>
<name>sshj</name>
<description>SSHv2 library for Java</description>

View File

@@ -20,6 +20,7 @@ import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/** This examples demonstrates how a remote command can be executed. */
public class Exec {
@@ -36,6 +37,7 @@ public class Exec {
try {
final Command cmd = session.exec("ping -c 1 google.com");
System.out.print(cmd.getOutputAsString());
cmd.join(5, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2010 Shikhar Bhushan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.schmizz.sshj;
import net.schmizz.sshj.transport.random.JCERandom;
import net.schmizz.sshj.transport.random.SingletonRandomFactory;
public class AndroidConfig extends DefaultConfig {
@Override
protected void initRandomFactory(boolean ignored) {
setRandomFactory(new SingletonRandomFactory(new JCERandom.Factory()));
}
}

View File

@@ -272,6 +272,11 @@ public abstract class AbstractChannel
close.await();
}
public void join(int timeout, TimeUnit unit)
throws ConnectionException {
close.await(timeout, unit);
}
protected synchronized void sendClose()
throws TransportException {
try {

View File

@@ -23,6 +23,7 @@ import net.schmizz.sshj.transport.TransportException;
import java.io.Closeable;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.TimeUnit;
/** A channel is the basic medium for application-layer data on top of an SSH transport. */
public interface Channel
@@ -138,4 +139,7 @@ public interface Channel
void join()
throws ConnectionException;
void join(int timeout, TimeUnit unit)
throws ConnectionException;
}

View File

@@ -35,10 +35,7 @@
*/
package net.schmizz.sshj.connection.channel.direct;
import net.schmizz.sshj.common.Buffer;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.common.SSHPacket;
import net.schmizz.sshj.common.StreamCopier;
import net.schmizz.sshj.common.*;
import net.schmizz.sshj.connection.Connection;
import net.schmizz.sshj.connection.ConnectionException;
import net.schmizz.sshj.connection.channel.ChannelInputStream;
@@ -50,9 +47,10 @@ import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/** {@link Session} implementation. */
public class
SessionChannel
/**
* {@link Session} implementation.
*/
public class SessionChannel
extends AbstractDirectChannel
implements Session, Session.Command, Session.Shell, Session.Subsystem {
@@ -66,6 +64,8 @@ public class
private Boolean canDoFlowControl;
private boolean usedUp;
public SessionChannel(Connection conn) {
super(conn, "session");
}
@@ -114,9 +114,11 @@ public class
@Override
public Command exec(String command)
throws ConnectionException, TransportException {
checkReuse();
log.info("Will request to exec `{}`", command);
sendChannelRequest("exec", true, new Buffer.PlainBuffer().putString(command))
.await(conn.getTimeout(), TimeUnit.SECONDS);
usedUp = true;
return this;
}
@@ -170,8 +172,7 @@ public class
@Override
public void reqX11Forwarding(String authProto, String authCookie, int screen)
throws ConnectionException,
TransportException {
throws ConnectionException, TransportException {
sendChannelRequest(
"x11-req",
true,
@@ -199,16 +200,20 @@ public class
@Override
public Shell startShell()
throws ConnectionException, TransportException {
checkReuse();
sendChannelRequest("shell", true, null).await(conn.getTimeout(), TimeUnit.SECONDS);
usedUp = true;
return this;
}
@Override
public Subsystem startSubsystem(String name)
throws ConnectionException, TransportException {
checkReuse();
log.info("Will request `{}` subsystem", name);
sendChannelRequest("subsystem", true, new Buffer.PlainBuffer().putString(name))
.await(conn.getTimeout(), TimeUnit.SECONDS);
usedUp = true;
return this;
}
@@ -238,4 +243,15 @@ public class
super.gotExtendedData(dataTypeCode, buf);
}
}
@Override
public void notifyError(SSHException error) {
err.notifyError(error);
super.notifyError(error);
}
private void checkReuse() {
if (usedUp)
throw new SSHRuntimeException("This session channel is all used up");
}
}

View File

@@ -181,7 +181,7 @@ public class StatefulSFTPClient
@Override
public void put(String source, String dest)
throws IOException {
super.get(source, cwdify(dest));
super.put(source, cwdify(dest));
}
}

View File

@@ -123,9 +123,6 @@ public final class SCPDownloadClient
return true;
case (char) 1:
addWarning(msg.substring(1));
break;
case (char) 2:
throw new SCPException("Remote SCP command returned error: " + msg.substring(1));

View File

@@ -61,7 +61,6 @@ abstract class SCPEngine {
final SessionFactory host;
final TransferListener listener;
final Queue<String> warnings = new LinkedList<String>();
Command scp;
int exitStatus;
@@ -86,19 +85,6 @@ abstract class SCPEngine {
return exitStatus;
}
public Queue<String> getWarnings() {
return warnings;
}
public boolean hadWarnings() {
return !warnings.isEmpty();
}
void addWarning(String warning) {
log.warn(warning);
warnings.add(warning);
}
void check(String what)
throws IOException {
int code = scp.getInputStream().read();
@@ -111,9 +97,7 @@ abstract class SCPEngine {
case 0: // OK
log.debug(what);
return;
case 1:
addWarning(readMessage());
break;
case 1: // Warning? not
case 2:
throw new SCPException("Remote SCP command had error: " + readMessage());
default:
@@ -123,7 +107,6 @@ abstract class SCPEngine {
void cleanSlate() {
exitStatus = -1;
warnings.clear();
}
void execSCPWith(List<Arg> args, String path)