Using R to download SAS file from ftp-server

时光总嘲笑我的痴心妄想 提交于 2019-11-29 12:07:23

As @MrFlick suggested, I solved this problem using getBinaryURL instead of getURL(). Also, I had to use the function write() instead of writeLines(). The result is as follows:

protocol <- "sftp"
server <- "ServerName"
userpwd <- "User:Pass"
tsfrFilename <- "/filepath/file.sas7bdat" 
ouptFilename <- "out.sas7bdat"

# Run #
## Download Data
url <- paste0(protocol, "://", server, tsfrFilename)
data <- getBinaryURL(url = url, userpwd=userpwd)

## Create File
fconn <- file(ouptFilename)
write(data, fconn)
close(fconn)

Alternatively, to transform the read data into R data frame, one can use the library haven, as follows

library(haven)
df_data=  read_sas(data)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!