public static SshServer getSsd(String shareDir)
{
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(9022);
sshd.setFileSystemFactory(new SftpFileSystem(shareDir));
//NO PASSWORDsshd.setPasswordAuthenticator
sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(
"hostkey.ser"));
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
//NO PASSWORD UserAuthNone.Factory()
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);
return sshd;
}
getSsd(shareDir).start();
public class DircotorSftpHome implements FileSystemView
{
private String currDir;
public DircotorSftpHome(String currDir)
{
this.currDir = currDir;
}
public SshFile getFile(String file) {
return getFile(currDir, file);
}
public SshFile getFile(SshFile baseDir, String file) {
return getFile(baseDir.getAbsolutePath(), file);
}
protected SshFile getFile(String dir, String file) {
// get actual file object
String physicalName = NativeSshFile.getPhysicalName("/",
dir, file, false);
File fileObj = new File(physicalName);
// strip the root directory and return
String userFileName = physicalName.substring("/".length() - 1);
return new SftpFile(physicalName, fileObj, "test");
}
public class SftpFileSystem implements FileSystemFactory
{
private String shareDir;
public SftpFileSystem(String shareDir)
{
this.shareDir = shareDir;
}
@Override
public FileSystemView createFileSystemView(Session session)
throws IOException
{
return new DircotorSftpHome(shareDir);
}
}
public class MyPasswordAuthenticator implements PasswordAuthenticator
{
private Log logger = LogFactory.getInstance(this);
@SuppressWarnings("deprecation")
@Override
public boolean authenticate(String username, String password,
ServerSession session)
{
return false;
}
}
{
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(9022);
sshd.setFileSystemFactory(new SftpFileSystem(shareDir));
//NO PASSWORDsshd.setPasswordAuthenticator
sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(
"hostkey.ser"));
List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
//NO PASSWORD UserAuthNone.Factory()
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);
return sshd;
}
getSsd(shareDir).start();
public class DircotorSftpHome implements FileSystemView
{
private String currDir;
public DircotorSftpHome(String currDir)
{
this.currDir = currDir;
}
public SshFile getFile(String file) {
return getFile(currDir, file);
}
public SshFile getFile(SshFile baseDir, String file) {
return getFile(baseDir.getAbsolutePath(), file);
}
protected SshFile getFile(String dir, String file) {
// get actual file object
String physicalName = NativeSshFile.getPhysicalName("/",
dir, file, false);
File fileObj = new File(physicalName);
// strip the root directory and return
String userFileName = physicalName.substring("/".length() - 1);
return new SftpFile(physicalName, fileObj, "test");
}
public class SftpFileSystem implements FileSystemFactory
{
private String shareDir;
public SftpFileSystem(String shareDir)
{
this.shareDir = shareDir;
}
@Override
public FileSystemView createFileSystemView(Session session)
throws IOException
{
return new DircotorSftpHome(shareDir);
}
}
public class MyPasswordAuthenticator implements PasswordAuthenticator
{
private Log logger = LogFactory.getInstance(this);
@SuppressWarnings("deprecation")
@Override
public boolean authenticate(String username, String password,
ServerSession session)
{
return false;
}
}