-
Notifications
You must be signed in to change notification settings - Fork 13
/
get_atlas_files.R
62 lines (51 loc) · 1.78 KB
/
get_atlas_files.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Required packages
library(yaml)
library(ssh)
library(fs)
# Define your output directory and base path on server
output_dir <- "/path/to/your/local/directory"
base_path_server <- "/path/to/server/base"
ssh_server <- "username:password@hostname"
atlas_version <- "v2.26"
# Load and parse the yaml file
file_dict <- yaml.load_file("atlas_output_files.yaml")[[atlas_version]]
# Create an SSH session (replace 'ssh_alias' with your SSH alias)
session <- ssh_connect(ssh_server)
# Function to download files or directories
download <- function(remote_path) {
# Create full path on server
full_remote_path <- file.path(base_path_server, remote_path, fsep = "/")
# Create full local path
local_path <- file.path(output_dir, remote_path)
# Check if the file already exists locally
if (dir.exists(local_path) || file.exists(local_path)) {
print(paste(local_path, "already exists. Skipping download."))
return(NULL)
}
tryCatch(
{
# Create local directory structure if it doesn't exist
dir.create(dirname(local_path), recursive = TRUE, showWarnings = FALSE)
# Download the file or directory
scp_download_dir(session, full_remote_path, local_path)
},
error = function(e) {
print(paste("Failed to download", full_remote_path, ":", e$message))
}
)
}
# Go through the parsed yaml data and download the files
for (key1 in names(file_dict)) {
value1 <- file_dict[[key1]]
if (is.character(value1)) {
# It's a direct path, download the file
download(value1)
} else if (is.list(value1)) {
# It's a nested list, go deeper
for (value2 in value1) {
download(value2)
}
}
}
# Close the SSH session
ssh_disconnect(session)