I've been working on this R library for FTP for a while now and my most recent endeavor is trying to make a function that deletes things from an FTP server. However, I've found myself bamboozled for quite a while now by this problem.
Here's my code for deleting the files:
ftpDelete <- function(credentials, address, directory, files) {
status <- integer(length(files))
names(status) <- files
pb <- txtProgressBar(min = 0, max = length(files), style = 3)
cd <- paste("CWD", directory)
for (n in 1:length(files)) {
sink("nul")
status[n] <- tryCatch({
dc <- paste("DELE", files[n])
k <- curlPerform(url = getFTPURL(address), quote = c(cd, dc), userpwd = credentials, returntransfer = 1)
0
}, error = function(w) {
return(1)
})
Sys.sleep(0.5)
sink()
setTxtProgressBar(pb, n)
}
close(pb)
return(status)
}
Every time I run this code, it seems to print out the full directory of the FTP folder, which is INCREDIBLY irritating, especially when I apply this function on a large amount of files. Do you guys have any advice / wisdom about how to hide the output? For reference, I'm using RStudio on Windows 10, and even with using sink() around the entire function call, I still get the entire directory printed. out.