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

1.2k views Asked by At

I need to upload a file using FTP in R, but the directory is up from my home directory on the server. When I run the following code using RCurl, I get this error: 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")

More specifically, I get this output:

> 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

It works when I try to upload to my home directory:

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

I guess the question is, how do I navigate between directories within the ftpUpload function? Or, if there is another way to upload a file from Windows to a Linux server in R, I am open to that too. Thanks in advance!

EDIT: I have write access to the directory in question, and am able to upload files in FileZilla. I cannot change my home directory on the server, unfortunately.

1

There are 1 answers

1
Dean MacGregor On BEST ANSWER

I don't have a FTP server to test this on but something like

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/")

The prequote argument should pass the command CWD (change working directory) to the server before it tries to interact with the given path. The reason filezilla works is because when you double click the '..' in the gui, it is sending the FTP server a CWD command.