How access to server with Rcurl using FTP protocol?

Hi community, I'm try to make the same access of this server like I do with FileZilla program.

Is my first time with this topic and I want learn very well.

I'm working on updating multiple folders on a remote server. I have the credentials, and the connection works well in FileZilla. However, I want to implement a more efficient method to streamline this process and avoid manual steps for update images. For that I'm using curl Rcurl.

The FileZilla settings:

With library(curl)

library(curl)
ftp_url <- "ftp://ftp.genesys-pgr.org/wiews/COL003/acn/G21366"
username <- "m"
password <- "FTPpassword"
port <- 2222

#for list file
list_files_ftp <- function(url, user, pwd, timeout = 50) {
  handle <- new_handle()
  
  handle_setopt(handle,
                userpwd = paste(user, pwd, sep = ":"),
                use_ssl = 2,  # CURLUSESSL_ALL
                ssl_verifypeer = FALSE,
                ssl_verifyhost = FALSE,
                ftp_use_epsv = TRUE,
                dirlistonly = TRUE,
                timeout = timeout)
  
  con <- curl(url, "r", handle = handle)
  file_list <- readLines(con)
  close(con)
  
  return(file_list)
}

file_list <- list_files_ftp(ftp_url, username, password, timeout = 60)
##  Error
# Error in open.connection(con, open = mode) : 
#   Timeout was reached: [ftp.genesys-pgr.org] Connection timeout after 10007 ms
# 6.open.connection(con, open = mode)
# 5.open(con, open = mode)
# 4.withCallingHandlers(open(con, open = mode), error = function(err) {
#   close(con)
# })
# 3.curl_connection(url, open, handle)
# 2.curl(url, "r", handle = handle)
# 1.list_files_ftp(ftp_url, username, password, timeout = 60)

With library(Rcurl)

RCurl::getURL(url = "ftp://m:FTPpassword@ftp.genesys-pgr.org/wiews/COL003/acn/G21338/G21338 pod.jpg") # Im try with // and \\

The idea is get the connection for update the images files in each folder.

Tnks for any advice.

A guy for my work help me to make the connection:

library(RCurl)
library(httr)

ftp_server <-'ftp.genesys-pgr.org'
file_path <- '/wiews/COL003/acn/G21366/G21366 .jpg' 
encoded_username_file_path <- URLencode(file_path) #  encoding
port <- 2222  

httr::set_config(httr::config(ssl_verifypeer=0L))

url <- paste0("ftps://", ftp_server,':', port, encoded_username_file_path)

binary_data <- getBinaryURL(url,
                            username='my_user',
                            password='my_password',
                            ftp.use.epsv = F,  
                            ssl.verifypeer = F,
                            ssl.verifyhost = F)

writeBin(binary_data, "G21366 seed.jpg")  # the name of download file.

And extra code for update files:

local_file_path <- 'my_local_filepath'

ftpUpload(
  what = local_file_path, 
  to = "ftps://ftp.genesys-pgr.org:2222/wiews/COL003/acn/G21366/G21366%20pod.jpg", # encode path for paste the new file
  userpwd = 'my_user:my_password',
  ftp.use.epsv = F, 
  ssl.verifypeer = F, 
  ssl.verifyhost = F, 
  verbose = T,
  connecttimeout = 30
)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.