Stéphane Laurent
Stéphane Laurent

Reputation: 84709

Creating a folder and deleting on a FTP server with RCurl

With the ftpUpload() function of the RCurl package for R, I am able to upload a file on a FTP server. But how to create a new folder on the FTP server from R ? And how to delete a file or a folder ?

Upvotes: 3

Views: 3772

Answers (5)

When using an SFTP server, the correct command would be "rm file.txt". To remove a file from a SFTP server using RCurl I build on @Ruggero Valentinotti his answer, using:

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

Upvotes: 0

user10892181
user10892181

Reputation: 11

To create a folder, use curlPerform("ftphost",quote="MKD foldername",userpwd="user:pass"). To delete a file, use curlPerform("ftphost",quote="DELETE filename",userpwd="user:pass"). Depending on the FTP server, you may have to use mkdir instead of MKD and del or DELE instead of DELETE. It depends on the server.

Upvotes: 0

giocomai
giocomai

Reputation: 3528

In order to create a new folder, you can simply include the full path when you upload a file, and enable the ftp.create.missing.dirs option:

.opts <- list(ftp.create.missing.dirs=TRUE)
user <- "yourlogin"
pwd <- "yourpassword"

RCurl::ftpUpload(what = "filename.txt", to = "ftp://yourserver.com:21/newFolder/filename.txt", userpwd = paste(user, pwd, sep = ":"), .opts = opts)

Upvotes: 3

Ruggero Valentinotti
Ruggero Valentinotti

Reputation: 31

It works for me, but the correct quote command is DELE, not DELETE! Here a list of commands http://www.nsftools.com/tips/RawFTP.htm

So try:

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

Upvotes: 3

MarkB42
MarkB42

Reputation: 725

Try using curlPerform to send quote commands. Try something like this to delete. You may have to look up the actual ftp commands for creating a dir and deleting a file.

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

Upvotes: 1

Related Questions