Last active
October 11, 2021 00:41
-
-
Save jjesusfilho/083e1adabe261cd992accc65b5c855b1 to your computer and use it in GitHub Desktop.
Listar arquivos de servidor remoto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listar_arquivos <- function(session, dir = ".", pattern = NULL, all = FALSE, recursive = FALSE, full_names = FALSE){ | |
if (all == TRUE & recursive == TRUE){ | |
argumento <- paste0("ls -a -R ",dir," | ","egrep ",pattern) | |
} else if (all == TRUE){ | |
argumento <- paste0("ls -a ",dir," | ","egrep ",pattern) | |
} else if (recursive == TRUE){ | |
argumento <- paste0("ls -R ",dir," | ","egrep ",pattern) | |
} else | |
argumento <- paste0("ls ",dir," | ","egrep ",pattern) | |
if (is.null(pattern)){ | |
argumento <- gsub("\\|.*","",argumento) | |
} | |
files <- ssh::ssh_exec_internal(session,argumento)$stdout %>% | |
rawToChar() %>% | |
strsplit("\n") %>% | |
unlist() | |
if (full_names == TRUE){ | |
fn <- ssh::ssh_exec_internal(session,"pwd")$stdout %>% | |
rawToChar() %>% | |
strsplit("\n") %>% | |
unlist() %>% | |
file.path(dir) | |
files <- file.path(fn,files) %>% | |
gsub("//","/",.) | |
} | |
files <- gsub("/root","",files) | |
files <- gsub("/~","",files) | |
return(files) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment