I am using RCurl for a project. I need to delete a file from a specific directory on the remote server. My issue, in short, is that I can log in successfully, then traverse to the directory in question. But the handle doesn't retain that location. So when I next set up a second command to delete the file, it can't find it (because I'm in the wrong directory). When I log in, it brings me (naturally) to my home directory.
What I thought would work would be to:
- Create a handle
- curlPerform to 'CWD' to the directory (this works!)
- do another curlPerform to delete the file. But the directory is not retained
between the two curlPerform commands.
h <- RCurl::getCurlHandle()
In the below, 'unpwd' is a username:pwd pair:
RCurl::curlSetOpt(.opts = list(verbose = TRUE,
userpwd = unpwd),
curl = h)
In the below code, 'x' is a string variable. URL lists the root directory (when I tried to further specify my homedir there, it bombs out. When I omit the home directory, it puts me there automatically, so then the directory traversal works. This took a lot of time to figure out!
RCurl::curlPerform(
url = "ftp://<URL>",
curl = h,
quote = paste0("CWD ChangeTo/", x, "/ThisDirectory/")
)
I'm good to here. It successfully lists the files. So now I try the following code. 'filenames' is a vector of the files contained in that directory (successfully obtained that in earlier code):
RCurl::curlPerform(url = paste0("<URL>/ChangeTo/", x, "/ThisDirectory/"),
curl = h,
quote = paste0("DELE ", filenames[1]))
But here it gives a 550 error: I am once again in my home directory so the file is not found there. My 'place' on the server is not retained.
The curl tutorial (URL: https://curl.se/docs/manual.html) states the following, which might explain the problem. In discussing multiple downloads, it states (in reference to downloads): Note that curl cannot use persistent connections for transfers that are used in subsequent curl invokes. Try to stuff as many URLs as possible on the same command line if they are using the same host, as that will make the transfers faster. If you use an HTTP proxy for file transfers, practically all transfers will be persistent.
If I try something like the following, I don't cwd into the correct directory, either (again, stuck in my home directory):
RCurl::curlPerform(
url = paste0("<URL>/~/ChangeTo/", x, "/ThisDirectory/"),
curl = h,
quote = paste0("DELE ", filenames[1])
)
So, I need to 'cwd' first, then somehow retain that location (it's not embedded in the handle) and then delete the file.
Worst case scenario, I can delete the files manually at the end using FileZilla, I guess. But so far as I know there is no proxy server on the remote server, nor can I install one.
Any and all thoughts greatly appreciated. Thanks!!!!