list files in a directory on an ssh server and save as a dataframe using R SSH package

Viewed 272

I'd like to grab the file names in a directory on an ssh server using the R SSH package and save the output as a dataframe. After establishing a connection, I've tried

files <- ssh_exec_internal(ssh_connection, command = 'ls /directory_of_interest')

This gives an output that does not resemble a list of file names. Any help would be appreciated

$status
[1] 0

$stdout
   [1] 32 30 32 30 30 38 32 36 2e 30 33 35 0a 32 30 32 30 30 38 32 37 2e 30 33 35 0a 32 30 32 30 30 38 32 38 2e 30 33 35 0a 32 30 32 30 30 38 32 39 2e
  [49] 30 33 35 0a 32 30 32 30 30 38 33 30 2e 30 33 35 0a 32 30 32 30 30 38 33 31 2e 30 33 35 0a 32 30 32 30 30 39 30 31 2e 30 33 35 0a 32 30 32 30 30
  [97] 39 30 32 2e 30 33 35 0a 32 30 32 30 30 39 30 33 2e 30 33 35 0a 32 30 32 30 30 39 30 34 2e 30 33 35 0a 32 30 32 30 30 39 30 35 2e 30 33 35 0a 32
 [145] 30 32 30 30 39 30 36 2e 30 33 35 0a 32 30 32 30 30 39 30 37 2e 30 33 35 0a 32 30 32 30 30 39 30 38 
 [ reached getOption("max.print") -- omitted 560 entries ]

$stderr
raw(0)
2 Answers

This worked for me:

rawToChar(as.raw(strtoi(files$stdout, 16L))) %>% read_table(cat(.), col_names="file")

The files in a server directory can be listed as follows:

files <- ssh_exec_internal(ssh_connection, "ls /directory_of_interest") %>%
    .[["stdout"]]  %>%
    rawToChar()    %>%
    strsplit("\n") %>%
    unlist()
Related