无法打开文件.curltmp。在 Rstudio 中使用curl_download 时出错

问题描述 投票:0回答:1

我尝试在 R-4.3.3 (Windows) 上从 ncbi 下载 ftp 文件,但失败,因为我不断收到以下错误。据我了解,download.files 不再适用于 ftp 文件,因为 ftp 的 wininet 已不存在,但可以接受任何替代方法。希望得到一些意见。

尝试过:

url <-"ftp://ftp.ncbi.nlm.nih.gov/refseq/M_musculus/mRNA_Prot/mouse.1.protein.faa.gz"
tmp <- "C:/Windows/Temp.curl"
curl_download(url, tmp)
Error in curl_download(url, tmp) : 
  Failed to open file C:\Windows\Temp.curl.curltmp.

预计:

download ftp file to destination tmp
r curl rcurl
1个回答
0
投票

第二个参数是目标文件;确保它位于您具有写入权限的某个现有目录中。默认情况下,

download.file()
在 Windows 中使用
libcurl
而不是
wininet
,至少对于
ftp://
URL 而言是如此。如果它在您的系统上表现不同,您可以通过
download.file.method
选项进行设置。无论如何,
curl::curl_download()
download.file()
都可以与 Windows 中的
ftp://
URL 配合使用:

url <-"ftp://ftp.ncbi.nlm.nih.gov/refseq/M_musculus/mRNA_Prot/mouse.1.protein.faa.gz"
# per-session temporary directory
tmp <- tempdir()

(cdl_out <- file.path(tmp, paste0("cdl_",basename(url))))
#> [1] "C:\\Users\\marguslt\\AppData\\Local\\Temp\\Rtmpcp5IMg/cdl_mouse.1.protein.faa.gz"
curl::curl_download(url, cdl_out)

(dlf_out <- file.path(tmp, paste0("dlf_",basename(url))))
#> [1] "C:\\Users\\marguslt\\AppData\\Local\\Temp\\Rtmpcp5IMg/dlf_mouse.1.protein.faa.gz"
download.file(url, dlf_out, mode = "wb")

# list downloaded files
fs::dir_info(tmp, glob = "*.gz")[1:3]
#> # A tibble: 2 × 3
#>   path                                                               type   size
#>   <fs::path>                                                         <fct> <fs:>
#> 1 …marguslt/AppData/Local/Temp/Rtmpcp5IMg/cdl_mouse.1.protein.faa.gz file  5.02M
#> 2 …marguslt/AppData/Local/Temp/Rtmpcp5IMg/dlf_mouse.1.protein.faa.gz file  5.02M

# system info and download.file.method
Sys.info()[1:3] 
#>       sysname       release       version 
#>     "Windows"      "10 x64" "build 19045"
options()$download.file.method
#> "libcurl"
© www.soinside.com 2019 - 2024. All rights reserved.