本文整理汇总了Java中org.apache.sshd.server.command.ScpCommandFactory类的典型用法代码示例。如果您正苦于以下问题:Java ScpCommandFactory类的具体用法?Java ScpCommandFactory怎么用?Java ScpCommandFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScpCommandFactory类属于org.apache.sshd.server.command包,在下文中一共展示了ScpCommandFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
public void init(Context context, Device device) {
sshd.setKeyExchangeFactories(Arrays.asList(
new DHG14.Factory(),
new DHG1.Factory()));
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(context.getFilesDir() + "/sftpd.ser"));
sshd.setFileSystemFactory(new AndroidFileSystemFactory(context));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setSubsystemFactories(Collections.singletonList((NamedFactory<Command>)new SftpSubsystem.Factory()));
if (device.publicKey != null) {
keyAuth.deviceKey = device.publicKey;
sshd.setPublickeyAuthenticator(keyAuth);
}
sshd.setPasswordAuthenticator(passwordAuth);
}
示例2: setupSftpServer
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
public void setupSftpServer() throws IOException {
sshd = SshServer.setUpDefaultServer();
sshd.setHost("127.0.0.1");
sshd.setPort(4922);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("target/hostkey.ser"));
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
return "ftpuser".equals(username) && "topsecret".equals(password);
}
});
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
// prepare directory for test files
VirtualFileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(ROOT.getAbsolutePath());
sshd.setFileSystemFactory(fileSystemFactory);
sshd.start();
}
示例3: start
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
public void start() {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(configuration.port());
sshd.setKeyPairProvider(keyPairProvider);
setupUserHomeDirectories();
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setPasswordAuthenticator(new SftpUserBackedPasswordAuthenticator(loginToUserDictionary()));
userAuthFactories.add(new UserAuthPublicKey.Factory());
sshd.setPublickeyAuthenticator(new SftpUserBackedPublicKeyAuthenticator(loginToUserDictionary()));
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
try {
sshd.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: setupSftpServer
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
/**
* Starts a SFTP server on port 22
*/
private void setupSftpServer() {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(9009);
//sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"/home/ravi/WORK/SUPPORT/JIRA/SKYTVNZDEV-26/SftpTest/dist/hostkey.ser"}));
ClassLoader classLoader = getClass().getClassLoader();
log.info("Using identity file: " + classLoader.getResource("sftp/id_rsa.pub").getFile());
File file = new File(classLoader.getResource("sftp/id_rsa.pub").getFile());
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(file.getAbsolutePath()));
System.out.println(file.getAbsolutePath());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthPublicKey.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
public boolean authenticate(String username, PublicKey key, ServerSession session) {
if ("sftpuser".equals(username)) {
return true;
}
return false;
}
});
sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
try {
sshd.start();
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: setUpServer
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
protected void setUpServer() throws Exception {
canTest = true;
try {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(getPort());
sshd.setKeyPairProvider(new FileKeyPairProvider(new String[]{"src/test/resources/hostkey.pem"}));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
PublickeyAuthenticator publickeyAuthenticator = new PublickeyAuthenticator() {
// consider all keys as authorized for all users
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return true;
}
};
sshd.setPublickeyAuthenticator(publickeyAuthenticator);
sshd.start();
} catch (Exception e) {
// ignore if algorithm is not on the OS
NoSuchAlgorithmException nsae = ObjectHelper.getException(NoSuchAlgorithmException.class, e);
if (nsae != null) {
canTest = false;
String name = System.getProperty("os.name");
String message = nsae.getMessage();
log.warn("SunX509 is not avail on this platform [{}] Testing is skipped! Real cause: {}", name, message);
} else {
// some other error then throw it so the test can fail
throw e;
}
}
}
示例6: createSshServer
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
private SshServer createSshServer( int port, String homeDir, String hostKeyPath ) {
SshServer server = SshServer.setUpDefaultServer();
server.setHost( "localhost" );
server.setPort( port );
server.setFileSystemFactory( new VirtualFileSystemFactory( homeDir ) );
server.setSubsystemFactories( Collections.<NamedFactory<Command>>singletonList( new SftpSubsystem.Factory() ) );
server.setCommandFactory( new ScpCommandFactory() );
server.setKeyPairProvider( new SimpleGeneratorHostKeyProvider( hostKeyPath ) );
server.setPasswordAuthenticator( this );
return server;
}
示例7: startSSHServer
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
@BeforeClass
public static void startSSHServer() throws Exception {
// Disable bouncy castle to avoid versions conflict
System.setProperty("org.apache.sshd.registerBouncyCastle", "false");
sshd = SshServer.setUpDefaultServer();
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>(1);
userAuthFactories.add(new UserAuthPassword.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
return username != null && username.equals(password);
}
});
sshd.setCommandFactory(new ScpCommandFactory(new CommandFactory() {
@Override
public Command createCommand(String command) {
String[] splitCommand;
if (OsUtils.isUNIX()) {
splitCommand = SSHInfrastructureHelper.splitCommand(command);
} else if (OsUtils.isWin32()) {
splitCommand = SSHInfrastructureHelper.splitCommandWithoutRemovingQuotes(command);
} else {
throw new IllegalStateException("Operating system is not recognized");
}
StringBuilder rebuiltCommand = new StringBuilder();
for (String commandPiece : splitCommand) {
rebuiltCommand.append(commandPiece).append(" ");
}
rebuiltCommand.trimToSize();
EnumSet<ProcessShellFactory.TtyOptions> ttyOptions;
if (OsUtils.isUNIX()) {
ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.ONlCr);
} else {
ttyOptions = EnumSet.of(ProcessShellFactory.TtyOptions.Echo,
ProcessShellFactory.TtyOptions.ICrNl,
ProcessShellFactory.TtyOptions.ONlCr);
}
if (OsUtils.isUNIX()) {
return new ProcessShellFactory(new String[] { "/bin/sh", "-c", rebuiltCommand.toString() },
ttyOptions).create();
} else {
return new ProcessShellFactory(new String[] { "cmd.exe", "/C", rebuiltCommand.toString() },
ttyOptions).create();
}
}
}));
sshd.start();
port = sshd.getPort();
javaExePath = System.getProperty("java.home") + File.separator + "bin" + File.separator +
(OsUtils.isWin32() ? "java.exe" : "java");
javaExePath = "\"" + javaExePath + "\"";
infraParams = new Object[] { ("localhost " + NB_NODES + "\n").getBytes(), //hosts
60000, //timeout
0, //attempts
10, //wait between failures
port, //ssh server port
"toto", //ssh username
"toto", //ssh password
new byte[0], // optional ssh private key
new byte[0], // optional ssh options file
javaExePath, //java path on the remote machines
PAResourceManagerProperties.RM_HOME.getValueAsString(), //Scheduling path on remote machines
OperatingSystem.getOperatingSystem(), "" }; // extra java options
policyParameters = new Object[] { AccessType.ALL.toString(), AccessType.ALL.toString(), "20000" };
}
示例8: before
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
@BeforeClass
public static void before() throws Exception {
sshd = SshServer.setUpDefaultServer();
sshd.setPort(2220);
sshd.setKeyPairProvider(createTestKeyPairProvider("target/test-classes/quickstarts/camel-ftp-binding/hostkey.pem"));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
//sshd.setFileSystemFactory(new org.apache.sshd.common.file.nativefs.NativeFileSystemFactory());
sshd.start();
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(2222);
serverFactory.addListener("default", listenerFactory.createListener());
ListenerFactory sslListenerFactory = new ListenerFactory();
sslListenerFactory.setPort(2221);
SslConfigurationFactory ssl = new SslConfigurationFactory();
ssl.setKeystoreFile(getFile("target/test-classes/quickstarts/camel-ftp-binding/ftpserver.jks"));
ssl.setKeystorePassword("password");
sslListenerFactory.setSslConfiguration(ssl.createSslConfiguration());
sslListenerFactory.setImplicitSsl(false); // Setting it to true will not read the file
serverFactory.addListener("ssl", sslListenerFactory.createListener());
PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
managerFactory.setFile(getFile("target/test-classes/quickstarts/camel-ftp-binding/ftp-users.properties"));
UserManager createUserManager = managerFactory.createUserManager();
serverFactory.setUserManager(createUserManager);
// This doesn't work due to class method signature mismatch
//NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
//fileSystemFactory.setCreateHome(true);
//serverFactory.setFileSystem(fileSystemFactory);
File file = new File("target/ftp/ftps");
file.mkdirs();
file = new File("target/ftp/sftp");
file.mkdirs();
JSch sch = new JSch();
Session session = sch.getSession("camel", "localhost", 2220);
session.setUserInfo(new SimpleUserInfo("isMyFriend"));
session.connect();
ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
c.connect();
System.out.println("Home: " + c.getHome());
c.chmod(777, ".");
c.chmod(777, "target");
c.chmod(777, "target/ftp");
c.chmod(777, "target/ftp/sftp");
c.disconnect();
session.disconnect();
ftpServer = serverFactory.createServer();
ftpServer.start();
startTestContainer(featureName, bundleName);
}
示例9: startUp
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
@BeforeClass
public static void startUp() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(2222);
serverFactory.addListener("default", listenerFactory.createListener());
ListenerFactory sslListenerFactory = new ListenerFactory();
sslListenerFactory.setPort(2221);
SslConfigurationFactory ssl = new SslConfigurationFactory();
ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
ssl.setKeystorePassword("password");
sslListenerFactory.setSslConfiguration(ssl.createSslConfiguration());
sslListenerFactory.setImplicitSsl(false); // Setting it to true will not read the file
serverFactory.addListener("ftps", sslListenerFactory.createListener());
PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
managerFactory.setFile(new File("src/test/resources/users.properties"));
UserManager createUserManager = managerFactory.createUserManager();
serverFactory.setUserManager(createUserManager);
NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
fileSystemFactory.setCreateHome(true);
serverFactory.setFileSystem(fileSystemFactory);
File file = new File("target/ftp/ftps");
file.mkdirs();
file = new File("target/ftp/sftp");
file.mkdirs();
ftpServer = serverFactory.createServer();
ftpServer.start();
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(2220);
sshd.setKeyPairProvider(createTestKeyPairProvider("src/test/resources/hostkey.pem"));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.start();
JSch sch = new JSch();
Session session = sch.getSession("camel", "localhost", 2220);
session.setUserInfo(new SimpleUserInfo("isMyFriend"));
session.connect();
ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
c.connect();
System.out.println("Home: " + c.getHome());
c.chmod(777, ".");
c.chmod(777, "target");
c.chmod(777, "target/ftp");
c.chmod(777, "target/ftp/sftp");
c.disconnect();
session.disconnect();
}
示例10: start
import org.apache.sshd.server.command.ScpCommandFactory; //导入依赖的package包/类
@Override
public void start() {
this.sshd = SshServer.setUpDefaultServer();
this.sshd.setPort(8022);
this.sshd.setHost("192.168.0.13");
this.sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(
"/Work/Keys/testsshdkeys"));
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
// userAuthFactories.add(new UserAuthPublicKey.Factory());
userAuthFactories.add(new UserAuthPassword.Factory());
this.sshd.setUserAuthFactories(userAuthFactories);
/*
* this.sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
*
* @Override public boolean authenticate(String user, PublicKey key,
* ServerSession session) { //session. return "jack".equals(user); } });
*/
this.sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String user, String password,
ServerSession sess) {
boolean auth = "jack".equals(user);
if (auth) {
ApiSession apisess = SshdModule.this.apimap.get(sess);
if (apisess == null) {
apisess = ApiSession.createLocalSession("root");
SshdModule.this.apimap.put(sess, apisess);
System.out.println("Adding ssh session: " + sess.getId());
} else
System.out.println("Reusing ssh session: " + sess.getId());
}
return auth;
}
});
// this.sshd.setCommandFactory(new ScpCommandFactory(new CommonCommandFactory()));
this.sshd.setCommandFactory(new ScpCommandFactory());
List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
this.sshd.setSubsystemFactories(namedFactoryList);
this.sshd.setFileSystemFactory(new FileSystemFactoryImpl(this));
try {
this.sshd.start();
} catch (Exception x) {
Logger.error("Error starting sshd module: " + x);
}
}