mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 15:50:57 +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;
|
private final FileAttributes attrs;
|
||||||
|
|
||||||
public RemoteResourceInfo(String parent, String name, FileAttributes attrs) {
|
public RemoteResourceInfo(String parent, String name, FileAttributes attrs) {
|
||||||
this.comps = new PathComponents(parent, name);
|
this(new PathComponents(parent, name), attrs);
|
||||||
this.attrs = attrs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getParent() {
|
public RemoteResourceInfo(PathComponents comps, FileAttributes attrs) {
|
||||||
return comps.getParent();
|
this.comps = comps;
|
||||||
|
this.attrs = attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return comps.getPath();
|
return comps.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getParent() {
|
||||||
|
return comps.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return comps.getName();
|
return comps.getName();
|
||||||
}
|
}
|
||||||
@@ -41,20 +45,12 @@ public class RemoteResourceInfo {
|
|||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isType(FileMode.Type type) {
|
|
||||||
return attrs.getType() == type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRegularFile() {
|
public boolean isRegularFile() {
|
||||||
return isType(FileMode.Type.REGULAR);
|
return attrs.getType() == FileMode.Type.REGULAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDirectory() {
|
public boolean isDirectory() {
|
||||||
return isType(FileMode.Type.DIRECTORY);
|
return attrs.getType() == FileMode.Type.DIRECTORY;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSymlink() {
|
|
||||||
return isType(FileMode.Type.SYMKLINK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -64,9 +64,10 @@ public class SFTPFileTransfer
|
|||||||
|
|
||||||
public void download(String source, String dest)
|
public void download(String source, String dest)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
PathComponents src = pathHelper.getComponents(source);
|
final PathComponents pathComponents = pathHelper.getComponents(source);
|
||||||
new Downloader(getModeSetter(), getDownloadFilter()).download(new RemoteResourceInfo(src.getParent(), src
|
final FileAttributes attributes = sftp.stat(source);
|
||||||
.getName(), sftp.stat(source)), new File(dest));
|
new Downloader(getModeSetter(), getDownloadFilter())
|
||||||
|
.download(new RemoteResourceInfo(pathComponents, attributes), new File(dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUploadFilter(FileFilter uploadFilter) {
|
public void setUploadFilter(FileFilter uploadFilter) {
|
||||||
@@ -136,12 +137,19 @@ public class SFTPFileTransfer
|
|||||||
void download(RemoteResourceInfo remote, File local)
|
void download(RemoteResourceInfo remote, File local)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
log.info("Downloading [{}] to [{}]", remote, local);
|
log.info("Downloading [{}] to [{}]", remote, local);
|
||||||
if (remote.isDirectory())
|
switch (remote.getAttributes().getType()) {
|
||||||
downloadDir(remote, local);
|
case DIRECTORY:
|
||||||
else if (remote.isRegularFile())
|
downloadDir(remote, local);
|
||||||
downloadFile(remote, local);
|
break;
|
||||||
else
|
case UNKNOWN: // ... BS servers like wodFTPD
|
||||||
throw new IOException(remote + " is not a regular file or directory");
|
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 {
|
try {
|
||||||
final FileInputStream fis = new FileInputStream(local);
|
final FileInputStream fis = new FileInputStream(local);
|
||||||
try {
|
try {
|
||||||
StreamCopier.copy(fis, //
|
StreamCopier.copy(fis, rf.getOutputStream(), sftp.getSubsystem().getRemoteMaxPacketSize()
|
||||||
rf.getOutputStream(), sftp.getSubsystem().getRemoteMaxPacketSize()
|
- rf.getOutgoingPacketOverhead(), false);
|
||||||
- rf.getOutgoingPacketOverhead(), false);
|
|
||||||
} finally {
|
} finally {
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user