sftp - How to Set Root Directory in Apache Mina Sshd Server in Java -
i use apache mina sshd api start local sftp server in java.in sftp client use jcraft jsch api create sftp client.i start server.the problem want write unit test cases check whether client can put files server's root directory. sftp server doesn't have root directory.so know there approach set server's root directory.
eg: c:\sftp how can set path server root directory.so client can read , write files every time connect server.thank you.
public class sftpserverstarter { private sshserver sshd; private final static logger logger = loggerfactory.getlogger(sftpserverstarter.class); public void start(){ sshd = sshserver.setupdefaultserver(); sshd.setport(22); sshd.sethost("localhost"); sshd.setpasswordauthenticator(new mypasswordauthenticator()); sshd.setpublickeyauthenticator(new mypublickeyauthenticator()); sshd.setkeypairprovider(new simplegeneratorhostkeyprovider()); sshd.setsubsystemfactories(arrays.<namedfactory<command>>aslist(new sftpsubsystem.factory())); sshd.setcommandfactory(new scpcommandfactory()); try { logger.info("starting ..."); sshd.start(); logger.info("started"); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); logger.info("can not start server"); } } }
in default takes root path system property called user.dir
inorder change this, can override getvirtualuserdir()
in nativefilesystemview
, return path.
sshd.setfilesystemfactory(new nativefilesystemfactory() { @override public filesystemview createfilesystemview(final session session) { return new nativefilesystemview(session.getusername(), false) { @override public string getvirtualuserdir() { return "c:\\myroot"; } }; }; });
Comments
Post a Comment