简体   繁体   English

通过R中的SCP发送文件

[英]Send file via SCP in R

I would like to copy a file from my computer to a remote server via SCP using R . 我想使用R通过SCP将文件从计算机复制到远程服务器。

I have found 2 functions that appear to satisfy this partially. 我发现2个函数似乎可以部分满足此要求。

1. Using ssh.utils 1.使用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 : 2.使用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. RCurl在scp()函数中似乎具有更强大的功能,但是据我所知,它仅用于将文件从远程复制到本地计算机。 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? 有没有其他方法可以使用这些功能,或者有其他功能可以通过SCP将文件从本地计算机复制到远程计算机?

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 , eg 解决交互输入密码需求的一种方法是在system调用中使用sshpass (请参阅https://stackoverflow.com/a/13955428/6455166 ),例如

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. 有关更多详细信息,请参见上面链接的答案,包括避免在命令中嵌入密码的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM