mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 07:40:55 +03:00
* sftp get: unknown file type, assume it is a regular file
* minor refactoring
This commit is contained in:
@@ -21,18 +21,22 @@ public class RemoteResourceInfo {
|
||||
private final FileAttributes attrs;
|
||||
|
||||
public RemoteResourceInfo(String parent, String name, FileAttributes attrs) {
|
||||
this.comps = new PathComponents(parent, name);
|
||||
this.attrs = attrs;
|
||||
this(new PathComponents(parent, name), attrs);
|
||||
}
|
||||
|
||||
public String getParent() {
|
||||
return comps.getParent();
|
||||
public RemoteResourceInfo(PathComponents comps, FileAttributes attrs) {
|
||||
this.comps = comps;
|
||||
this.attrs = attrs;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return comps.getPath();
|
||||
}
|
||||
|
||||
public String getParent() {
|
||||
return comps.getParent();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return comps.getName();
|
||||
}
|
||||
@@ -41,20 +45,12 @@ public class RemoteResourceInfo {
|
||||
return attrs;
|
||||
}
|
||||
|
||||
public boolean isType(FileMode.Type type) {
|
||||
return attrs.getType() == type;
|
||||
}
|
||||
|
||||
public boolean isRegularFile() {
|
||||
return isType(FileMode.Type.REGULAR);
|
||||
return attrs.getType() == FileMode.Type.REGULAR;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return isType(FileMode.Type.DIRECTORY);
|
||||
}
|
||||
|
||||
public boolean isSymlink() {
|
||||
return isType(FileMode.Type.SYMKLINK);
|
||||
return attrs.getType() == FileMode.Type.DIRECTORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,9 +64,10 @@ public class SFTPFileTransfer
|
||||
|
||||
public void download(String source, String dest)
|
||||
throws IOException {
|
||||
PathComponents src = pathHelper.getComponents(source);
|
||||
new Downloader(getModeSetter(), getDownloadFilter()).download(new RemoteResourceInfo(src.getParent(), src
|
||||
.getName(), sftp.stat(source)), new File(dest));
|
||||
final PathComponents pathComponents = pathHelper.getComponents(source);
|
||||
final FileAttributes attributes = sftp.stat(source);
|
||||
new Downloader(getModeSetter(), getDownloadFilter())
|
||||
.download(new RemoteResourceInfo(pathComponents, attributes), new File(dest));
|
||||
}
|
||||
|
||||
public void setUploadFilter(FileFilter uploadFilter) {
|
||||
@@ -136,12 +137,19 @@ public class SFTPFileTransfer
|
||||
void download(RemoteResourceInfo remote, File local)
|
||||
throws IOException {
|
||||
log.info("Downloading [{}] to [{}]", remote, local);
|
||||
if (remote.isDirectory())
|
||||
downloadDir(remote, local);
|
||||
else if (remote.isRegularFile())
|
||||
downloadFile(remote, local);
|
||||
else
|
||||
throw new IOException(remote + " is not a regular file or directory");
|
||||
switch (remote.getAttributes().getType()) {
|
||||
case DIRECTORY:
|
||||
downloadDir(remote, local);
|
||||
break;
|
||||
case UNKNOWN: // ... BS servers like wodFTPD
|
||||
log.warn("Server did not supply information about the type of file at `{}` -- assuming it is a regular file!");
|
||||
case REGULAR:
|
||||
downloadFile(remote, local);
|
||||
break;
|
||||
default:
|
||||
throw new IOException(remote + " is not a regular file or directory");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,9 +248,8 @@ public class SFTPFileTransfer
|
||||
try {
|
||||
final FileInputStream fis = new FileInputStream(local);
|
||||
try {
|
||||
StreamCopier.copy(fis, //
|
||||
rf.getOutputStream(), sftp.getSubsystem().getRemoteMaxPacketSize()
|
||||
- rf.getOutgoingPacketOverhead(), false);
|
||||
StreamCopier.copy(fis, rf.getOutputStream(), sftp.getSubsystem().getRemoteMaxPacketSize()
|
||||
- rf.getOutgoingPacketOverhead(), false);
|
||||
} finally {
|
||||
fis.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user