mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 07:40:55 +03:00
minor
This commit is contained in:
@@ -85,13 +85,33 @@ public class SFTPFileTransfer
|
|||||||
|
|
||||||
private class Downloader {
|
private class Downloader {
|
||||||
|
|
||||||
private void setAttributes(final RemoteResourceInfo remote, final File local)
|
private void download(final RemoteResourceInfo remote, final File local)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final FileAttributes attrs = remote.getAttributes();
|
log.info("Downloading [{}] to [{}]", remote, local);
|
||||||
getModeSetter().setPermissions(local, attrs.getMode().getPermissionsMask());
|
switch (remote.getAttributes().getType()) {
|
||||||
if (getModeSetter().preservesTimes() && attrs.has(FileAttributes.Flag.ACMODTIME)) {
|
case DIRECTORY:
|
||||||
getModeSetter().setLastAccessedTime(local, attrs.getAtime());
|
downloadDir(remote, local);
|
||||||
getModeSetter().setLastModifiedTime(local, attrs.getMtime());
|
break;
|
||||||
|
case UNKNOWN:
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void downloadDir(final RemoteResourceInfo remote, final File local)
|
||||||
|
throws IOException {
|
||||||
|
final File adjusted = FileTransferUtil.getTargetDirectory(local, remote.getName());
|
||||||
|
setAttributes(remote, adjusted);
|
||||||
|
final RemoteDirectory rd = sftp.openDir(remote.getPath());
|
||||||
|
try {
|
||||||
|
for (RemoteResourceInfo rri : rd.scan(getDownloadFilter()))
|
||||||
|
download(rri, new File(adjusted.getPath(), rri.getName()));
|
||||||
|
} finally {
|
||||||
|
rd.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,40 +133,21 @@ public class SFTPFileTransfer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadDir(final RemoteResourceInfo remote, final File local)
|
private void setAttributes(final RemoteResourceInfo remote, final File local)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final File adjusted = FileTransferUtil.getTargetDirectory(local, remote.getName());
|
final FileAttributes attrs = remote.getAttributes();
|
||||||
setAttributes(remote, adjusted);
|
getModeSetter().setPermissions(local, attrs.getMode().getPermissionsMask());
|
||||||
final RemoteDirectory rd = sftp.openDir(remote.getPath());
|
if (getModeSetter().preservesTimes() && attrs.has(FileAttributes.Flag.ACMODTIME)) {
|
||||||
try {
|
getModeSetter().setLastAccessedTime(local, attrs.getAtime());
|
||||||
for (RemoteResourceInfo rri : rd.scan(getDownloadFilter()))
|
getModeSetter().setLastModifiedTime(local, attrs.getMtime());
|
||||||
download(rri, new File(adjusted.getPath(), rri.getName()));
|
|
||||||
} finally {
|
|
||||||
rd.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void download(final RemoteResourceInfo remote, final File local)
|
|
||||||
throws IOException {
|
|
||||||
log.info("Downloading [{}] to [{}]", remote, local);
|
|
||||||
switch (remote.getAttributes().getType()) {
|
|
||||||
case DIRECTORY:
|
|
||||||
downloadDir(remote, local);
|
|
||||||
break;
|
|
||||||
case UNKNOWN:
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Uploader {
|
private class Uploader {
|
||||||
|
|
||||||
void upload(File local, String remote)
|
private void upload(File local, String remote)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
log.info("Uploading [{}] to [{}]", local, remote);
|
log.info("Uploading [{}] to [{}]", local, remote);
|
||||||
if (local.isDirectory())
|
if (local.isDirectory())
|
||||||
|
|||||||
Reference in New Issue
Block a user