]> git.argeo.org Git - lgpl/argeo-commons.git/blob - Sftp.java
df4dd3a01d1a3354e1477b0914aa053f110fd085
[lgpl/argeo-commons.git] / Sftp.java
1 package org.argeo.ssh;
2
3 import java.io.IOException;
4 import java.net.URI;
5 import java.nio.file.FileSystem;
6 import java.nio.file.Path;
7
8 import org.apache.sshd.client.subsystem.sftp.fs.SftpFileSystem;
9
10 public class Sftp extends AbstractSsh {
11 private URI uri;
12
13 private SftpFileSystem fileSystem;
14
15 public Sftp(URI uri) {
16 this.uri = uri;
17 openSession(uri);
18 }
19
20 public FileSystem getFileSystem() {
21 if (fileSystem == null) {
22 try {
23 authenticate();
24 fileSystem = getSftpFileSystemProvider().newFileSystem(getSession());
25 } catch (IOException e) {
26 throw new IllegalStateException(e);
27 }
28 }
29 return fileSystem;
30 }
31
32 public Path getBasePath() {
33 String p = uri.getPath() != null ? uri.getPath() : "/";
34 return getFileSystem().getPath(p);
35 }
36
37 }