You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by djangofan <dj...@gmail.com> on 2018/05/12 18:58:55 UTC
Help, I cannot figure out how to set starting folder of SFTP server
Help, I cannot figure out how to set starting folder of SFTP server.
Specifically, I have a web service that is able to transfer files to a SFTP
server and I want to use Mina/HTTPD to host a temporary server just for
unit test purpose. So, therfore I want the FTP server to host files in my
project root, and not show files outside of my project root.
For example, this doesn't work for me. I get an error:
sshd.setFileSystemFactory(new
VirtualFileSystemFactory(Paths.get("src/test/resources")));
And the error I get when trying to connect is:
20: Invalid filename
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2367)
at com.jcraft.jsch.ChannelSftp.getHome(ChannelSftp.java:2437)
Note: If I don't set the VirtualFileSystemFactory at all, then I can ftp
files to my server with no error but the server root is my entire file
system, which is NOT desirable.
One thing I tried was this, which explains the desired behavior I want, but
it I get a compile error (Error:(97, 13) java: method does not override or
implement a method from a supertype) :
sshd.setFileSystemFactory(new VirtualFileSystemFactory() {
@Override
protected Path computeRootDir(Session session) throws
IOException {
return Paths.get(".");
}
});
My Maven deps are:
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>apache-sshd</artifactId>
<version>1.7.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
</dependency>
My basic setup is:
sshd = SshServer.setUpDefaultServer();
sshd.setPort(port);
sshd.setKeyPairProvider(new
SimpleGeneratorHostKeyProvider(Paths.get(PUBLIC_CERT_FILE)));
sshd.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new LenientPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new LenientPublicKeyAuthenticator());
I also posted my question here:
https://stackoverflow.com/questions/50302137/apache-mina-cannot-set-starting-folder-of-sftp-server
--
Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-User-Forum-f31345.html
Re: Help, I cannot figure out how to set starting folder of SFTP
server
Posted by Michael Fritscher <mi...@telematik-zentrum.de>.
Hi,
your first way sounds right - I do a
"
FileSystemFactory fsf = new VirtualFileSystemFactory(new
File(root).toPath());
sshd.setFileSystemFactory(fsf);
"
in m code. Only difference: I use absolute paths.
Best regards,
Michael Fritscher
On 12.05.2018 20:58, djangofan wrote:
> Help, I cannot figure out how to set starting folder of SFTP server.
>
> Specifically, I have a web service that is able to transfer files to a SFTP
> server and I want to use Mina/HTTPD to host a temporary server just for
> unit test purpose. So, therfore I want the FTP server to host files in my
> project root, and not show files outside of my project root.
>
> For example, this doesn't work for me. I get an error:
>
> sshd.setFileSystemFactory(new
> VirtualFileSystemFactory(Paths.get("src/test/resources")));
>
> And the error I get when trying to connect is:
>
> 20: Invalid filename
>
> at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
> at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2367)
> at com.jcraft.jsch.ChannelSftp.getHome(ChannelSftp.java:2437)
>
> Note: If I don't set the VirtualFileSystemFactory at all, then I can ftp
> files to my server with no error but the server root is my entire file
> system, which is NOT desirable.
>
> One thing I tried was this, which explains the desired behavior I want, but
> it I get a compile error (Error:(97, 13) java: method does not override or
> implement a method from a supertype) :
>
> sshd.setFileSystemFactory(new VirtualFileSystemFactory() {
> @Override
> protected Path computeRootDir(Session session) throws
> IOException {
> return Paths.get(".");
> }
> });
>
> My Maven deps are:
>
> <dependency>
> <groupId>org.apache.sshd</groupId>
> <artifactId>apache-sshd</artifactId>
> <version>1.7.0</version>
> <type>pom</type>
> </dependency>
>
>
> <dependency>
> <groupId>com.jcraft</groupId>
> <artifactId>jsch</artifactId>
> <version>0.1.54</version>
> </dependency>
>
> My basic setup is:
>
> sshd = SshServer.setUpDefaultServer();
> sshd.setPort(port);
> sshd.setKeyPairProvider(new
> SimpleGeneratorHostKeyProvider(Paths.get(PUBLIC_CERT_FILE)));
> sshd.setSubsystemFactories(Arrays.asList(new SftpSubsystemFactory()));
> sshd.setCommandFactory(new ScpCommandFactory());
> sshd.setPasswordAuthenticator(new LenientPasswordAuthenticator());
> sshd.setPublickeyAuthenticator(new LenientPublicKeyAuthenticator());
>
>
> I also posted my question here:
> https://stackoverflow.com/questions/50302137/apache-mina-cannot-set-starting-folder-of-sftp-server
>
>
>
>
>
> --
> Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-User-Forum-f31345.html
--
ZfT - Zentrum für Telematik e.V.
Michael Fritscher
Magdalene-Schoch-Straße 5
97074 Würzburg
Tel: +49 (931) 615 633 - 57
Fax: +49 (931) 615 633 - 11
Email: michael.fritscher@telematik-zentrum.de
Web: http://www.telematik-zentrum.de
Vorstand:
Prof. Dr. Klaus Schilling, Hans-Joachim Leistner
Sitz: Gerbrunn
USt.-ID Nr.: DE 257 244 580, Steuer-Nr.: 257/111/70203
Amtsgericht Würzburg, Vereinsregister-Nr.: VR 200 167