从SFTP服务器读取Excel文件

huangapple go评论76阅读模式
英文:

Read Excel-file from sftp server

问题

我想从一个受密码保护的ftp服务器读取一个.xlsx文件到我的R中。

使用getURL,我能够访问文件并获取它们的名称,例如"sftp://datasource.eex-group.com/market_data/power/ch/derivatives/xls/2023/PowerFutureHistory_CH_2023.xlsx",但然后我不知道如何在R中读取/导入这个xlsx文件。

如果路径名中有空格,例如"sftp://datasource.eex-group.com/market data/power/ch/derivatives/xls/2023/PowerFutureHistory_CH_2023.xlsx",这会有问题吗?

英文:

I would like to read an .xlsx-File from a password protected ftp-Server into my R.

With getURL I'm able to address the files and get their names, for example "sftp://datasource.eex-group.com/market_data/power/ch/derivatives/xls/2023/PowerFutureHistory_CH_2023.xlsx", but then I don't know how to read/import this xlsx-file into R.

Is it a problem, if the path name has a blank, e.g. "sftp://datasource.eex-group.com/market data/power/ch/derivatives/xls/2023/PowerFutureHistory_CH_2023.xlsx"

答案1

得分: 0

感谢您的评论。

关于密码保护部分,我在https://stackoverflow.com/questions/5420506/reading-information-from-a-password-protected-site 找到了答案。关于下载Excel/CSV文件,我在https://stackoverflow.com/questions/59645148/how-to-simply-download-an-excel-file-directly-from-the-internet-with-r 找到了相关信息。

结合使用时,它完美运行。

url = "sftp://user:passwd@server:port";

file.server <- paste0(url, path.server, "Excelfile_name_server.xlsx");

file.local <- paste0(path.local, "Excelfile_name_local.xlsx");

download.file(file.server, destfile = file.local, mode = "wb");
英文:

Thanks for the comments.

I found the answer on https://stackoverflow.com/questions/5420506/reading-information-from-a-password-protected-site for the password protected part and https://stackoverflow.com/questions/59645148/how-to-simply-download-an-excel-file-directly-from-the-internet-with-r
for downloading the excel/csv-file.

In combination it works perfectly.

url = &quot;sftp://user:passwd@server:port&quot;

file.server &lt;- paste0(url, path.server, &quot;Excelfile_name_server.xlsx&quot;)

file.local &lt;- paste0(path.local, &quot;Excelfile_name_local.xlsx&quot;)

download.file(file.server, destfile = file.local, mode = &quot;wb&quot;)

huangapple
  • 本文由 发表于 2023年5月10日 23:11:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76220077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定