Skip to content

Instantly share code, notes, and snippets.

@jjesusfilho
Last active October 11, 2021 00:41
Show Gist options
  • Save jjesusfilho/083e1adabe261cd992accc65b5c855b1 to your computer and use it in GitHub Desktop.
Save jjesusfilho/083e1adabe261cd992accc65b5c855b1 to your computer and use it in GitHub Desktop.
Listar arquivos de servidor remoto
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