我在使用ftpUpload()
的{{1}}功能将文件上传到SFTP中不存在的文件夹时遇到问题。我希望使用RCurl
选项创建文件夹(如果不存在)。这是我目前的代码:
ftp.create.missing.dirs
它似乎无法正常工作,因为我收到以下错误:
.opts <- list(ftp.create.missing.dirs=TRUE)
ftpUpload(what = "test.txt",
to "sftp://ftp.testserver.com:22/newFolder/existingfile.txt",
userpwd = paste(user, pwd, sep = ":"), .opts = opts)`
我可以将文件成功上传到现有文件夹,只是当文件夹不存在时我才会收到错误。
答案 0 :(得分:1)
问题似乎是因为您正在尝试创建新文件夹,如此问题所示:Create an remote directory using SFTP / RCurl
可以在Microsoft R Open git页面中找到该错误:
case SSH_SFTP_CLOSE:
if(sshc->sftp_handle) {
rc = libssh2_sftp_close(sshc->sftp_handle);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
else if(rc < 0) {
infof(data, "Failed to close libssh2 file\n");
}
sshc->sftp_handle = NULL;
}
if(sftp_scp)
Curl_safefree(sftp_scp->path);
在代码中,参数rc
与libssh2_sftp_close
函数(此处为https://www.libssh2.org/libssh2_sftp_close_handle.html的更多信息)相关,它会尝试关闭不存在的目录,从而导致错误。
尝试使用curlPerform:
curlPerform(url="ftp.xxx.xxx.xxx.xxx/";, postquote="MkDir /newFolder/", userpwd="user:pass")