rcurl :: geturl如何仅列出文件夹中的文件URL
我想在远程SFTP服务器中列出文件,因此我这样做了:
url <- "sftp://remoteserver.com/dir/"
credentials <- "myusrname/mypwd"
file_list <- tryCatch({
RCurl::getURL(
url,
userpwd = credentials,
ftp.use.epsv = FALSE,
dirlistonly = TRUE,
forbid.reuse = TRUE,
.encoding = "UTF-8"
)
}, error = function(e) {
as.character()
})
但是,在file_list
中,除了该文件夹中的文件的URL外,我也有一些我不''的额外条目。需要:
# at the beginning of the vector
[1] "sftp://remoteserver.com/dir/."
[2] "sftp://remoteserver.com/dir/.."
# at the end of the vector
[67] "sftp://remoteserver.com/dir/"
有没有办法避免这些条目?使用以下代码删除它们是安全的吗?
file_list <- file_list[c(-1, -2)]
file_list <- file_list[-length(file_list)]
I want to list the files in a remote SFTP server, so I did this:
url <- "sftp://remoteserver.com/dir/"
credentials <- "myusrname/mypwd"
file_list <- tryCatch({
RCurl::getURL(
url,
userpwd = credentials,
ftp.use.epsv = FALSE,
dirlistonly = TRUE,
forbid.reuse = TRUE,
.encoding = "UTF-8"
)
}, error = function(e) {
as.character()
})
However, in file_list
, except for the URLs of the files in that folder, there are also some extra entries that I don't need:
# at the beginning of the vector
[1] "sftp://remoteserver.com/dir/."
[2] "sftp://remoteserver.com/dir/.."
# at the end of the vector
[67] "sftp://remoteserver.com/dir/"
Is there a way to avoid these entries? Is it safe to use the following code to just delete them?
file_list <- file_list[c(-1, -2)]
file_list <- file_list[-length(file_list)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这不是最好的方法,以防它并不总是按顺序排列。如果您想要一个.logs文件的所有内容,那么我会做这样的事情:
I don't think that's the best method in case it's not always in that order. If you want everything that is a .logs file, then I'd do something like this: