2

I searched the other threads, but it can´t get any solution. I try to upload a file with PHP an cURL to a remote server. With pure FTP it works fine:

$fp = fopen('testfile.jpg', 'r');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"ftp://server.com/testfile.jpg");
curl_setopt($curl, CURLOPT_USERPWD, "username:password");

curl_setopt($curl, CURLOPT_UPLOAD, 1);  
curl_setopt($curl, CURLOPT_INFILE, $fp);

curl_exec ($curl);
curl_close ($curl);

But switching to SFTP or even SCP does not work. I tried SFTP by putting an s prior to the URL (sftp://server.com/testfile.jpg) and added the additional code line curl_setopt($curl, CURLPROTO_SFTP, 1);

No success. I get this error: Upload failed: Operation failed (4/-31)

What can I do? Any suggestions? Thank you

  • Possible duplicate of [Uploading files with SFTP](https://stackoverflow.com/questions/9572314/uploading-files-with-sftp) – cgrim Oct 05 '18 at 17:59
  • 1
    It should work with sftp if you specify the full target path, such as `sftp://server.com/home/user/testfile.jpg` - if you try that does it fix it? – drew010 Oct 05 '18 at 20:00
  • Thank you very much, with the full path given, it works! – user3475261 Oct 06 '18 at 08:21
  • How can I add SFTP authentification via private and public key to the cURL request? The remote server is a backup strage system, which the hosting company provides me a pair of public&private keys for logging on. – user3475261 Oct 06 '18 at 08:23

0 Answers0