简体   繁体   English

带有 RCurl 的 sftp 协议 - 最后一步,如何将 libcurl 的 R 路径从 usr/lib 更改为 usr/local/lib

[英]sftp protocol with RCurl - last step, how to change R path to libcurl from usr/lib to usr/local/lib

First off - I know this isn't a specific code problem, so feel free to vote to close the question, but I've spent the better part of half of my day today struggling with this problem and could use some help.首先 - 我知道这不是一个特定的代码问题,所以可以随意投票结束这个问题,但我今天花了大半天的时间来解决这个问题,可以使用一些帮助。 I also think this thread can help anybody trying to get sftp protocol working in R, since I'll share what I've done today.我也认为这个线程可以帮助任何试图让 sftp 协议在 R 中工作的人,因为我将分享我今天所做的事情。

I have been attempting to update RCurl so it supports sftp protocol.我一直在尝试更新 RCurl,使其支持 sftp 协议。 In R, my protocols look as such (with version and host as well):在 R 中,我的协议看起来是这样(还有版本和主机):

> library(RCurl)
> curlVersion()$protocols
 [1] "dict"   "file"   "ftp"    "ftps"   "gopher" "http"   "https"  "imap"   "imaps"  "ldap"   "ldaps"  "pop3"   "pop3s"  "rtsp"   "smb"    "smbs"  
[17] "smtp"   "smtps"  "telnet" "tftp" 

> curlVersion()$version
[1] "7.43.0"

> curlVersion()$host
[1] "x86_64-apple-darwin15.0"

Not great - no sftp option...不是很好 - 没有 sftp 选项...

I followed this thread - http://andrewberls.com/blog/post/adding-sftp-support-to-curl - to update curl on my machine, and was partially successful in doing so.我按照这个线程 - http://andrewberls.com/blog/post/adding-sftp-support-to-curl - 在我的机器上更新 curl,并且部分成功。 The success part is reflected in when I run the following in the command line:成功部分反映在我在命令行中运行以下内容时:

curl -V 
curl 7.55.1 (x86_64-apple-darwin15.6.0) libcurl/7.55.1 zlib/1.2.5 
libssh2/1.8.0
Release-Date: 2017-08-14
Protocols: dict file ftp gopher http imap ldap ldaps pop3 rtsp scp sftp smtp telnet tftp 
Features: AsynchDNS IPv6 Largefile libz UnixSockets 

This is great, because I've got curl updated.这很棒,因为我已经更新了 curl。 However, when I load RCurl and run curlVersion() in R, it's not updated.但是,当我加载 RCurl 并在 R 中运行 curlVersion() 时,它没有更新。 I've examined the lib folders of my /usr/ directory and have the following problem.我检查了我的 /usr/ 目录的 lib 文件夹并遇到以下问题。 In both my /usr/lib AND /usr/local/lib, there exists libcurl files.在我的 /usr/lib 和 /usr/local/lib 中,都存在 libcurl 文件。 Specifically:具体来说:

  • libcurl.3.dylib, libcurl.4.dylib, and libcurl.dylib in /usr/lib /usr/lib 中的 libcurl.3.dylib、libcurl.4.dylib 和 libcurl.dylib
  • libcurl.4.dylib, libcurl.dylib, libcurl.a and libcurl.la in /usr/local/lib /usr/local/lib 中的 libcurl.4.dylib、libcurl.dylib、libcurl.a 和 libcurl.la

The files in my /usr/local/lib directory are the new files that I'd like used, however here is where my major headache began.我的 /usr/local/lib 目录中的文件是我想要使用的新文件,但是这里是我最头疼的地方。 I copied the four files from /usr/local/lib into /usr/lib and I BROKE MY COMPUTER.我将这四个文件从 /usr/local/lib 复制到 /usr/lib 并损坏了我的计算机。 Many of my applications stopped loading, and I had to reinstall my OS X on account of being afraid of messing anything else up.我的许多应用程序停止加载,我不得不重新安装我的 OS X,因为我害怕弄乱其他任何东西。 When I reinstalled my OS X, it put my files back into their respective folders (how they look in the bullets above).当我重新安装 OS X 时,它会将我的文件放回各自的文件夹中(它们在上面的项目符号中的外观)。

If I had to guess, I probably shouldn't have moved the .a or .la files... I'm not sure.如果我不得不猜测,我可能不应该移动 .a 或 .la 文件......我不确定。

One last thing - when i run $ $PATH in console, I get:最后一件事 - 当我在控制台中运行 $ $PATH 时,我得到:

$PATH
-bash: /Users/Home/.rvm/gems/ruby-2.3.3/bin:/Users/Home/.rvm/gems/ruby-2.3.3@global/bin:/Users/Home/.rvm/rubies/ruby-2.3.3/bin:/Users/Home/anaconda2/bin:/usr/local/git/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/Users/Home/.rvm/bin: No such file or directory

/usr/local/bin is before /usr/bin. /usr/local/bin 在 /usr/bin 之前。 but I don't see anything with /usr/local/lib or /usr/lib - could I add these (/usr/local/lib) to my path to fix this?但我没有看到 /usr/local/lib 或 /usr/lib 的任何内容 - 我可以将这些 (/usr/local/lib) 添加到我的路径中来解决这个问题吗? .libPaths() in R gives me this: R 中的 .libPaths() 给了我这个:

.libPaths()
"/Library/Frameworks/R.framework/Versions/3.4/Resources/library"

...if it helps at all ...如果它有帮助的话

EDIT - I should note that the root of all problems, ofcourse, is that since 'sftp' is not listed in curlVersion()$protocols in R, that when i run RCurl::getURL(), or RCurl::ftpUpload() (im hoping to use ftpUpload), for both I receive the error:编辑 - 我应该注意到所有问题的根源,当然,是因为 'sftp' 没有在 R 中的 curlVersion()$protocols 中列出,当我运行 RCurl::getURL() 或 RCurl::ftpUpload() (我希望使用 ftpUpload),对于我收到的错误:

> RCurl::ftpUpload(what = 'myfile.txt', to = 'sftp://userid:userpw@ip/'myfile.txt')
Error in function (type, msg, asError = TRUE)  : 
  Protocol "sftp" not supported or disabled in libcurl

Thanks!谢谢!

Phew!呼! Finally got this working in an Ubuntu 14.04 docker container with rstudio-server.最终在带有 rstudio-server 的 Ubuntu 14.04 docker 容器中实现了这个功能。 I hit every issue!我击中了每一个问题! But I had to spend more hours than I care to count finding all this stuff, so trying to put it all in one place for anyone else having this problem Here's what I did...但是我不得不花费更多的时间来计算找到所有这些东西,所以试图将所有这些都放在一个地方,供其他遇到此问题的人使用这就是我所做的......

In the linux terminal:在 Linux 终端中:

apt-get install libcurl4-openssl-dev

wget libssh2 and then compile with ordinary

./configure

make

make install

wget curl and then compile

./configure --with-sshlib2=/usr/local

make

make install

If you need curl to work in the terminal with sftp, it still may not at this point.如果您需要 curl 在带有 sftp 的终端中工作,此时可能仍然无法使用。 Verify its using the new libcurl.so.4 that you just installed.使用您刚刚安装的新 libcurl.so.4 验证它。 The curl you just installed will install into /usr/local/bin, so use ldd to verify its not using an old library.您刚刚安装的 curl 将安装到 /usr/local/bin 中,因此请使用 ldd 来验证它没有使用旧库。 Mine was using an old libcurl so I linked the old libcurl to the new libcurl in /usr/local/lib and then recompiled curl.我使用的是旧的 libcurl,所以我将旧的 libcurl 链接到 /usr/local/lib 中的新 libcurl,然后重新编译 curl。

If you want RCurl to work, copy all of the new libs from /usr/local/lib (libcurl & libssh2) to /lib, then move to the R console.如果您希望 RCurl 工作,请将所有新库从 /usr/local/lib(libcurl 和 libssh2)复制到 /lib,然后移至 R 控制台。

In Rconsole:在 Rconsole 中:

install.packages("RCurl", type = "source")

verify sftp protocol is enabled验证 sftp 协议已启用

libcurlVersion() RCurl::curlVersion() libcurlVersion() RCurl::curlVersion()

These should show you enabled protocols for libcurl and RCurl respectively.这些应该分别显示为 libcurl 和 RCurl 启用的协议。 Cross your fingers for sftp!为 sftp 交叉你的手指!

Just in case, I also did these things that probably didn't do much but I did when I was hitting a wall and just kept in place.以防万一,我也做了这些可能没有太大作用的事情,但我在撞墙时做了,只是保持原地不动。

upgraded R and R studio-server升级的 R 和 R 工作室服务器

removed the R version of curl and RCurl prior to reinstalling RCurl.在重新安装 RCurl 之前删除了 curl 和 RCurl 的 R 版本。 Also in newer rstudio am not sure the type="source" is needed.同样在较新的 rstudio 中,我不确定是否需要 type="source"。

Also as Canovice noted, be careful moving around libcurl and libssh libraries.同样正如 Canovice 所指出的,在 libcurl 和 libssh 库之间移动时要小心。 I broke networking a couple of times, fortunately since it was a docker container I just restarted.我中断了几次网络,幸运的是因为它是我刚刚重新启动的 docker 容器。 I found that moving everything at once worked best,我发现一次移动所有东西效果最好,

cp /usr/local/lib/libssh* /lib && cp /usr/local/lib/libcurl* /lib

Should also note I'm a total R novice so there may be cleaner ways to do this than moving libraries all over the place.还应该注意我是一个完全的 R 新手,所以可能有比在整个地方移动库更干净的方法来做到这一点。 I tried utilizing .libaths( ) in rstudio, but gave up in the end.我尝试在 rstudio 中使用.libaths( ),但最终放弃了。

In practice i've found it more dangerous to try updating an existing curl and openssl installation, than installing an entirely new version and updating PATH envars where they'll be used在实践中,我发现尝试更新现有的curlopenssl安装比安装全新版本并更新将使用它们的PATH envars 更危险

In my case my newer curl and openssl with sftp support where installed into在我的情况下,我较新的curlopenssl支持 sftp 安装到

/usr/local/opt/curl-openssl/bin
/usr/local/opt/openssl/lib/

Consequently I needed to set the following envars因此我需要设置以下环境

PATH="/usr/local/opt/curl-openssl/bin:${PATH}"
LIBRARY_PATH="/usr/local/opt/openssl/lib/:${LIBRARY_PATH}"

before executing执行前

install.packages("RCurl", type="source")

Installing RCurl from source did the trick for me !从源代码安装 RCurl 对我有用!

install.packages("RCurl", type="source")

I found the solution here - http://www.omegahat.net/RCurl/FAQ.html - specifically, the following lines.我在这里找到了解决方案 - http://www.omegahat.net/RCurl/FAQ.html - 特别是以下几行。

"I can't use scp or sftp within RCurl but the documentation for curl seems to suggest that it can. So why does RCurl not support it? “我不能在 RCurl 中使用 scp 或 sftp,但 curl 的文档似乎表明它可以。那么为什么 RCurl 不支持它?

RCurl does support it, but the likely problem is that the version of libcurl you have installed does not support it. RCurl 确实支持它,但可能的问题是您安装的 libcurl 版本不支持它。 You can check what protocols your libcurl and hence RCurl supports via the command curlVersion.您可以通过命令 curlVersion 检查您的 libcurl 以及 RCurl 支持的协议。 If scp and sftp are not there, reinstall libcurl but with support using libssh2.如果 scp 和 sftp 不存在,请重新安装 libcurl,但支持使用 libssh2。 You will need to have the libssh2 development libraries and headers installed before installing libcurl.在安装 libcurl 之前,您需要安装 libssh2 开发库和头文件。 On some OSes, you will need to rebuild RCurl from source."在某些操作系统上,您需要从源代码重建 RCurl。”

In general, this is a great summary of my issue from start to finish.总的来说,这是对我的问题从头到尾的一个很好的总结。 If your version of RCurl doesn't support sftp, you need to install (at the command line) libssh2 first, then reinstall libcurl, then rebuild from source for some reason.如果您的 RCurl 版本不支持 sftp,您需要先(在命令行)安装 libssh2,然后重新安装 libcurl,然后出于某种原因从源代码重建。

暂无
暂无

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

相关问题 将R库从/ usr / lib / R /库迁移到自定义库 - Migrating R library from /usr/lib/R/library to a custom library 带R的sftp-sftp不是带有RCurl的协议 - sftp with R - sftp not a protocol with RCurl 如何修复 R 中的“gcc:错误:“/usr/lib64/R/library/Rhdf5lib/lib/libhdf5.a”:没有这样的文件或目录 - How to fix 'gcc: error: “/usr/lib64/R/library/Rhdf5lib/lib/libhdf5.a”: No such file or directory' in R TwitteR r包:/usr/lib/x86_64-linux-gnu/libcurl.so.4:找不到版本`CURL_OPENSSL_3' - TwitteR r package: /usr/lib/x86_64-linux-gnu/libcurl.so.4: version `CURL_OPENSSL_3' not found dyld:库未加载:/usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib - dyld: Library not loaded: /usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib R package 安装:ld:警告:找不到选项“-L/usr/local/gfortran/lib”的目录 - R package installation: ld: warning: directory not found for option '-L/usr/local/gfortran/lib' 使用R时在Mac上找不到`/ usr / local / clang6 / lib / libomp.dylib` - `/usr/local/clang6/lib/libomp.dylib` not found on Mac when using R 闪亮的错误:“ / usr / bin / R:第238行:/ usr / lib / R / etc / ldpaths:权限被拒绝” - Shiny error: “/usr/bin/R: line 238: /usr/lib/R/etc/ldpaths: Permission denied” 在库“/usr/lib/R/lib/libR.so”中找不到 rpy2 错误符号“R_tryCatchError” - rpy2 error symbol 'R_tryCatchError' not found in library '/usr/lib/R/lib/libR.so' 安装 R Bioconductor package 时,'lib = "/usr/lib/R/library"' is not writable" - 'lib = "/usr/lib/R/library"' is not writable" while installing R Bioconductor package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM