如何使用 RCurl 中的 FTP 将文件上传到从主目录向上的目录?

How to upload file to directory that is up from home directory using FTP in RCurl?

我需要在 R 中使用 FTP 上传一个文件,但该目录位于服务器上我的主目录之上。当我 运行 以下代码使用 RCurl 时,出现此错误: 550 var: No such file or directory:

ftpUpload(what = "./plots/daily/LastTwentyFour.png",
      to = "ftp://spider/../../var/www/dashboard/img/LastTwentyFour.png",
      verbose = TRUE,
      userpwd = "REDACTED:REDACTED")

更具体地说,我得到了这个输出:

> PWD
< 257 "/home/dhadley" is the current directory
* Entry path is '/home/dhadley'
> CWD var
* ftp_perform ends with SECONDARY: 0
< 550 var: No such file or directory
* Server denied you to change to the given directory
* Connection #0 to host spider left intact
Error in function (type, msg, asError = TRUE)  : 
Server denied you to change to the given directory

当我尝试上传到我的主目录时有效:

ftpUpload(what = "./plots/daily/LastTwentyFour.png",
      to = "ftp://spider/LastTwentyFour.png",
      verbose = TRUE,
      userpwd = "REDACTED:REDACTED")

我想问题是,如何在 ftpUpload 函数内的目录之间导航?或者,如果有另一种方法可以将文件从 Windows 上传到 R 中的 Linux 服务器,我也愿意接受。提前致谢!

编辑:我对相关目录具有写入权限,并且能够在 FileZilla 中上传文件。不幸的是,我无法更改服务器上的主目录。

我没有 FTP 服务器来测试这个,但是

ftpUpload(what = "./plots/daily/LastTwentyFour.png",
  to = "ftp://spider/var/www/dashboard/img/LastTwentyFour.png",
  verbose = TRUE,
  userpwd = "REDACTED:REDACTED", prequote="CWD  /var/www/dashboard/img/")

prequote 参数应该在服务器尝试与给定路径交互之前将命令 CWD(更改工作目录)传递给服务器。 filezilla 工作的原因是当您双击 gui 中的“..”时,它会向 FTP 服务器发送一个 CWD 命令。