stenevang / sftp

R-package with convenience functions for SFTP operations wrapping RCurl functions
GNU General Public License v3.0
34 stars 17 forks source link

Unspecified error on upload #13

Open jzadra opened 2 years ago

jzadra commented 2 years ago

Trying to upload, and I get the following (this is on a different system than my other issue):

Upload from folder: xxx
SFTP destination: xxx
2 file(s) to upload.
Error in function (type, msg, asError = TRUE)  : 

There is no other error info. I enabled logging, and nothing is in the log.

Same thing happens when trying sftp_list()

stenevang commented 2 years ago

The error you see is caused by how libcurl was built and installed on the operating system you have. For example, see this: https://stackoverflow.com/questions/13171550/sftp-support-for-curl-on-osx (my R-package sftp uses another R-package RCurl which is an implementation for R of curl (https://curl.se/) which means RCurl has a dependency on libcurl).

jzadra commented 2 years ago

Like i said, this is on a different system (linux). The issue was more about the fact that the error doesn't state what the error is.

jzadra commented 2 years ago

Per that SO page, it suggests checking 'curl - V' to see if sftp is installed. on the linux box I'm using, it is installed, but I'm still getting that error.

stenevang commented 2 years ago

What do you get if you run RCurl::curlVersion()$protocols in R on that Linux box?

jzadra commented 2 years ago

RCurl::curlVersion()$protocols [1] "dict" "file" "ftp" "ftps" "gopher" "http" "https" "imap" "imaps" "ldap" "ldaps" "pop3" "pop3s" "rtmp" "rtsp" "scp" "sftp" "smb" "smbs" "smtp" "smtps" "telnet" "tftp"

stenevang commented 2 years ago

If you type just sftp::sftp_upload and press enter you will see the R code content of that function. You could copy the part of that which is the actual call to RCurl::ftpUpload and run that manually to see if that exposes a better error message. Or, you can copy the following:

# create sftp_con with sftp::sftp_connect and your specific details
f = "name_of_your.file"
fromfolder = getwd()
sftp_connection = sftp_con
filesource = file.path(fromfolder, f)
fileurl    <- paste0(sftp_connection$url, "/", f)
port       <- sftp_connection$port
userpwd    <- sftp_connection$userpass
timeout    <- sftp_connection$timeout
RCurl::ftpUpload(what = filesource,
                           asText = FALSE,
                           to = fileurl,
                           port = port,
                           userpwd = userpwd,
                           connecttimeout = timeout)
jzadra commented 2 years ago

Here's what I get:

> RCurl::ftpUpload(what = filesource,
+                  asText = FALSE,
+                  to = fileurl,
+                  port = port,
+                  userpwd = userpwd,
+                  connecttimeout = timeout)
Error in function (type, msg, asError = TRUE)  : 

I get the same thing when I use the RCurl code from sftp_list.

stenevang commented 2 years ago

OK. So now we know the error is specific for RCurl and not introduced by any code in the sftp package. Your next step is to Google the error message "Error in function (type, msg, asError = TRUE)" and "RCurl" and see if anyone has posted anything about a similar problem. For example, this Stackoverflow posting says a firewall traffic restriction caused the error: https://stackoverflow.com/questions/59203675/error-in-function-type-msg-aserror-true-in-r

jzadra commented 2 years ago

Yep will do, thanks for the help. I'll report back if/when I have a solution.

BerriJ commented 2 years ago

I had the very same Problem some weeks ago using RCurl. The trick was to set "ssl.verifyhost" and "ssl.verifypeer" to FALSE. Those are TRUE on default.

filenames <- RCurl::getURL(url,
        userpwd = userpwd,
        ftp.use.epsv = FALSE,
        dirlistonly = TRUE,
        ssl.verifyhost = FALSE,
        ssl.verifypeer = FALSE,
        verbose = T
    )
BerriJ commented 2 years ago

Quick Update. So I was able to reproduce the same (meaningless) error message using the sftp_list function. However, specifying curl_options solved that problem:

sftp_list(con,
    curl_options = list(
        "ssl.verifyhost" = "false",
        "ssl.verifypeer" = "false"
    )
)

sftp_upload has that same curl_options argument. So you may want to give that a try.