0

I need to push a file to a remote server from within R. It needs to be atomic (or nearly atomic). Conceptually, my idea was to first scp it to a tmp directory, and then move it to its final destination. What's a good way to do this from R? I'm on a Linux system, if that's relevant.

DavidR
  • 810
  • 2
  • 8
  • 16
  • Can you provide a more reproducible example or be more specific about what you are trying to do? For example, what do you mean by atomic? Binary data? – nrussell Feb 19 '15 at 17:26
  • 2
    I suspect "atomic" here means the file magically appears in one place complete and not gradually as it gets transferred. The remote server should never see half a file. Right? – Spacedman Feb 19 '15 at 17:28
  • Yes @Spacedman that's what I meant. – DavidR Feb 19 '15 at 17:44

1 Answers1

3

Use system calls in R. Something like:

system("scp foo.dat remote:/tmp/foo.dat.tmp")
system("ssh remote mv /tmp/foo.dat.tmp /drop/foo.dat")

you might need some extra parameters to ssh

you might also want to generate a random number for the temporary file name.

of course this need scp/ssh server and mv at the server, so easiest with GNU/Linux at both ends.

and you should probably check the return status of the scp command to see if it completed successfully or not before attempting the mv.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • Thanks. I tried this, and it works, except any command I submit to my R shell (from emacs or from Vim) while the second command is still running is ignored by R, which is really weird behavior. I may submit a second stackoverflow question about this. – DavidR Feb 19 '15 at 17:43
  • The problem I was having had to do with ssh eating subsequent commands sent to the R shell. c.f. http://stackoverflow.com/questions/28838273/calling-ssh-with-system-in-r-shell-eats-subsequent-commands/28842197#28842197 – DavidR Mar 15 '15 at 19:13