0

I would like to copy a file from my computer to a remote server via SCP using R.

I have found 2 functions that appear to satisfy this partially.

1. Using ssh.utils

ssh.utils::cp.remote(path.src="~/myfile.txt",
                     remote.dest="username@remote",
                     remote.src="", path.dest="~/temp", verbose=TRUE)

I've noticed that with this method, if I need to enter a password (when remote doesn't have my public key), the function produces an error.

2. Using RCurl:

RCurl appears to have more robust functionality in the scp() function, but, from what I can tell, it is only for copying a file from a remote to my local machine. I would like to do the opposite.

Is there another way to use these functions or is there another function that would be able to copy a file from my local machine to a remote machine via SCP?

Megatron
  • 15,909
  • 12
  • 89
  • 97
  • Can you elaborate on "the function produces an error" for your method 1? I tried this method, was prompted to enter my password, and managed to copy the file successfully, so I cannot reproduce the error. – Weihuang Wong Jul 05 '18 at 19:08
  • The error I received was that the command exited with status 1. No further details and no password prompt. – Megatron Jul 05 '18 at 19:19

1 Answers1

0

One approach to address the need to enter a password interactively is to use sshpass (see https://stackoverflow.com/a/13955428/6455166) in a call to system, e.g.

system('sshpass -p "password" scp ~/myfile.txt username@remote.com:/some/remote/path')

See the linked answer above for more details, including options to avoid embedding the password in the command.

Weihuang Wong
  • 12,868
  • 2
  • 27
  • 48