Search in sources :

Example 1 with ScpCommandFactory

use of org.apache.sshd.server.scp.ScpCommandFactory in project testcases by coheigea.

the class SFTPTest method setup.

@Before
public void setup() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(10000);
    // Write port number to configuration file in target
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    // Read in camel configuration file and substitute in the correct port
    File f = new File(basedir + "/src/test/resources/camel-sftp.xml");
    FileInputStream inputStream = new FileInputStream(f);
    String content = IOUtils.toString(inputStream, "UTF-8");
    inputStream.close();
    content = content.replaceAll("portno", "" + port);
    File f2 = new File(basedir + "/target/test-classes/camel-sftp.xml");
    FileOutputStream outputStream = new FileOutputStream(f2);
    IOUtils.write(content, outputStream, "UTF-8");
    outputStream.close();
    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);
    // Generate a key
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get("target/generatedkey.pem")));
    List<NamedFactory<Command>> subsystemFactories = new ArrayList<NamedFactory<Command>>(1);
    subsystemFactories.add(new SftpSubsystemFactory());
    sshServer.setSubsystemFactories(subsystemFactories);
    sshServer.setCommandFactory(new ScpCommandFactory());
    sshServer.setPasswordAuthenticator(new CamelPasswordAuthenticator());
    sshServer.start();
    // Create "storage_sftp" directory (delete it first if it exists)
    File storageDirectory = new File(basedir + "/target/storage_sftp");
    if (storageDirectory.exists()) {
        storageDirectory.delete();
    }
    storageDirectory.mkdir();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory) ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) Command(org.apache.sshd.server.Command) FileOutputStream(java.io.FileOutputStream) NamedFactory(org.apache.sshd.common.NamedFactory) File(java.io.File) Before(org.junit.Before)

Example 2 with ScpCommandFactory

use of org.apache.sshd.server.scp.ScpCommandFactory in project testcases by coheigea.

the class SCPTest method setup.

@Before
public void setup() throws Exception {
    int port = AvailablePortFinder.getNextAvailable(10000);
    // Write port number to configuration file in target
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    // Read in camel configuration file and substitute in the correct port
    File f = new File(basedir + "/src/test/resources/camel-scp.xml");
    FileInputStream inputStream = new FileInputStream(f);
    String content = IOUtils.toString(inputStream, "UTF-8");
    inputStream.close();
    content = content.replaceAll("portno", "" + port);
    File f2 = new File(basedir + "/target/test-classes/camel-scp.xml");
    FileOutputStream outputStream = new FileOutputStream(f2);
    IOUtils.write(content, outputStream, "UTF-8");
    outputStream.close();
    sshServer = SshServer.setUpDefaultServer();
    sshServer.setPort(port);
    // Generate a key
    sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get("target/generatedkey.pem")));
    sshServer.setCommandFactory(new ScpCommandFactory());
    sshServer.setPasswordAuthenticator(new CamelPasswordAuthenticator());
    sshServer.start();
    setupKnownHosts(port);
    // Create "storage" directory (delete it first if it exists)
    File storageDirectory = new File(basedir + "/target/storage");
    if (storageDirectory.exists()) {
        storageDirectory.delete();
    }
    storageDirectory.mkdir();
}
Also used : SimpleGeneratorHostKeyProvider(org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider) ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 3 with ScpCommandFactory

use of org.apache.sshd.server.scp.ScpCommandFactory in project wildfly-camel by wildfly-extras.

the class EmbeddedSSHServer method setupSftp.

public void setupSftp() {
    this.sshServer.setCommandFactory(new ScpCommandFactory());
    this.sshServer.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory()));
}
Also used : ScpCommandFactory(org.apache.sshd.server.scp.ScpCommandFactory) SftpSubsystemFactory(org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory)

Aggregations

ScpCommandFactory (org.apache.sshd.server.scp.ScpCommandFactory)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 SimpleGeneratorHostKeyProvider (org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider)2 SftpSubsystemFactory (org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 NamedFactory (org.apache.sshd.common.NamedFactory)1 Command (org.apache.sshd.server.Command)1