I’m trying to setup a mock SFTP server using Apache Mina. I have downloaded this Maven dependency …
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-sftp</artifactId>
<version>0.11.0</version>
<scope>test</scope>
</dependency>
Then I have this method for setting up the SFTP server …
private void setupSftpServer(final Integer sftpPort) throws IOException
{
final SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(sftpPort);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
final List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
userAuthFactories.add(new UserAuthNone.Factory());
sshd.setUserAuthFactories(userAuthFactories);
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator(){
@Override
public boolean authenticate(String arg0,
PublicKey arg1,
ServerSession arg2)
{
return true;
}
}
);
sshd.setCommandFactory(new ScpCommandFactory());
final List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
sshd.start();
} //
However, upon running this, I get the NoClassDefFoundError …
java.lang.NoClassDefFoundError: org/bouncycastle/crypto/prng/VMPCRandomGenerator
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.apache.sshd.common.random.BouncyCastleRandom.<init>(BouncyCastleRandom.java:56)
at org.apache.sshd.common.random.BouncyCastleRandom$Factory.create(BouncyCastleRandom.java:48)
at org.apache.sshd.common.random.BouncyCastleRandom$Factory.create(BouncyCastleRandom.java:41)
at org.apache.sshd.common.random.SingletonRandomFactory.<init>(SingletonRandomFactory.java:37)
at org.apache.sshd.SshBuilder$BaseBuilder.fillWithDefaultValues(SshBuilder.java:117)
at org.apache.sshd.SshBuilder$ServerBuilder.fillWithDefaultValues(SshBuilder.java:365)
at org.apache.sshd.SshBuilder$ServerBuilder.fillWithDefaultValues(SshBuilder.java:361)
at org.apache.sshd.SshBuilder$BaseBuilder.build(SshBuilder.java:234)
at org.apache.sshd.SshBuilder$BaseBuilder.build(SshBuilder.java:254)
at org.apache.sshd.SshServer.setUpDefaultServer(SshServer.java:366)
at org.mainco.subco.myproject.service.myprojectStudentServiceTest.setupmyprojectSftpServer(myprojectStudentServiceTest.java:1221)
at org.mainco.subco.myproject.service.myprojectStudentServiceTest.testSftpStudentFile(myprojectStudentServiceTest.java:1201)
What dependency do I need to include to get this class?
download from here www.bouncycastle.org/latest_releases.html
eg. bcprov-jdk15on-154.jar
then add this code