Siobhan
Siobhan

Reputation: 173

Delete files from SFTP using R Studio

I need to delete files from an FTP site once I have processed them in R (parsing content). However, nothing I try seems to work.

this is what ive trying, and variations of.

library(RCurl)

curlPerform(url="sftp://user:password@sftplocation/folder/", quote="DELE filename.pdf")

curlPerform(url="ftp://xxx.xxx.xxx.xxx/", quote="DELE file.txt", userpwd = "user:pass")

Error is Error in function (type, msg, asError = TRUE) : Unknown SFTP command

When I run the following code, I get a lovely list of all the files (which is used to download them). So I know the connection is working just great, and the parsing from the downloaded files works great!

curlPerform(url="sftp://user:password@sftplocation/folder/")

Thanks, Siobhan

Upvotes: 4

Views: 1419

Answers (1)

Spacedman
Spacedman

Reputation: 94237

To delete over sftp, use rm instead of DELE - which looks like an ftp rather than an sftp command.

Then make sure you have the full file path. This works for me:

curlPerform(
 url="sftp://[email protected]/", 
.opts=list(
   ssh.public.keyfile=pub,
   ssh.private.keyfile=pri),
   verbose=TRUE,
   quote="rm  /home/me/test/test.txt")

Note I've put my credentials in some key files so I don't put the password in plain text in the code.

I'm not convinced this is the best way to do it, since I can't stop it printing the contents of the URL... There's might be an option...

Upvotes: 2

Related Questions