8

I'm attempting to use the ftpUpload in the RCurl package for the first time.

The site I'm trying to access uses the sftp protocol. I've made sure to install the version of libcurl that includes the ability to make secure connections.

SFTP is listed among the protocols available to RCurl:

curlVersion()$protocols
[1] "dict"   "file"   "ftp"    "ftps"   "gopher"
[6] "http"   "https"  "imap"   "imaps"  "ldap"  
[11] "pop3"   "pop3s"  "rtmp"   "rtsp"   "scp"   
[16] "sftp"   "smtp"   "smtps"  "telnet" "tftp"

Yet, when I run the fileUpload function I get:

ftpUpload(what = "some_file.png",
          to = "userid:password@sftp://ec2-some-server-ip.compute-1.amazonaws.com")

Error in function (type, msg, asError = TRUE)  : 
Couldn't resolve host 'sftp'

I have also tried breaking the userid and password out in terms of parameterization, but I get the same response.

Any suggestions would be appreciated.

Statwonk
  • 713
  • 1
  • 8
  • 21
  • 1
    your `to` does not look like a valid path. I would expect it to look more like: "sftp://ec2-some-server-ip.comput-1.amazonaws.com/path/to/some_file.png". Also, is "some_file.png" the name of a file in your working directory? – GSee Sep 04 '12 at 17:14
  • I've tried both just pointing to the root and then also a sub-folder within the root like you suggest. Although I hadn't tried putting the actual file name at the end. That still gives the same message. Yes, the `some_file.png` is in my working directory. – Statwonk Sep 04 '12 at 17:23
  • Did you try using "ftp://..." instead of "sftp://..."? – GSee Sep 04 '12 at 17:40
  • Yes, and all variants of path strings. Same message. – Statwonk Sep 04 '12 at 17:54
  • I'm wondering if `ftpUpload` actually support sftp. I think I might need to user `curlPerform()`. Another thing I'm thinking might be a problem is that `ftpUpload` specifies port 80 by default. My sftp site uses port 22, so I've changed the path to be "sftp://ec2-some-server-ip.comput-1.amazonaws.com:22/path/". Still no luck, though. – Statwonk Sep 04 '12 at 18:41
  • Have you tried constructing it as the help file suggests? "One can specify the user login and password via the userpwd option for curlPerform via the ... parameter, or one can put this information directly in the target URL (i.e. to) in the form ftp://login:password@machine.name/path/to/file" - yours looks backwards. – TARehman Sep 04 '12 at 19:53
  • Yes, I've tried both including the login and password in the URL, and also breaking them out as parameters passed to curlPerform. I'm really skeptical that `ftpUpload` can accept an sftp address, so I'm going to try to work with `curlPerform` generally. My understanding is that `ftpUpload` is just a wrapper for `curlPerform`. – Statwonk Sep 04 '12 at 20:09
  • It is understandable to be skeptical since `?ftpUpload` says that `to` "should be the ftp server with the prefix 'ftp://'" :-) And you are correct that `ftpUpload` is just a wrapper, but look at its source -- it's a pretty thin wrapper. Everything is pretty much just passed through. So, if it's possible with `curlPerform`, it's probably possible with `ftpUpload` – GSee Sep 04 '12 at 21:16
  • I figured out the solution! It was partly that I originally hadn't specified the file path correctly as GSee pointed out. I needed to write the file name in the sftp path. The second problem was that I needed to specify port 22 in the file path. GSee, if you want to write a small blurb to that effect in the answer, I'll mark it so you can get credit. Thank you! – Statwonk Sep 05 '12 at 16:50
  • Hrm, so now I have authentication issues. I get `SSH authentication methods available: publickey,password`. I wonder if there's a way to simply use password authentication? – Statwonk Sep 05 '12 at 18:05
  • 1
    @Topher, I think you should post an answer and accept it since I'm sort of guessing, and you know exactly what your call looks like. – GSee Sep 05 '12 at 18:50

1 Answers1

9

The userid and password need to be after the protocol (thats why you're getting the cannot find host sftp error):

ftpUpload(what = "some_file.png",
      to = "sftp://userid:password@ec2-some-server-ip.compute-1.amazonaws.com:22/path/some_file.png")

I also suggest including the port number after the host in case it's not the default and the file path on the server where you want it to go.

RichardE
  • 116
  • 1
  • 5