Jump to content

Upload Textfile using cURL & SFTP


stevesimo

Recommended Posts

Hi, I have a textfile which I need to upload to a remote server but am getting no joy.

 

Can anyone spot what might be causing the problem from my code.  I have substituted ip address and username and password:

 

$localfile = 'test.txt';
  $ch = curl_init();
  $fp = fopen ($localfile, "r") or die('Cannot open textfile');
  curl_setopt($ch, CURLOPT_URL,"sftp://123.123.123.123:10022/username/test.txt");
  curl_setopt($ch, CURLOPT_USERPWD, "username:password");
  curl_setopt($ch, CURLOPT_UPLOAD, 1);
  curl_setopt($ch, CURLOPT_INFILE, $fp);
  if(curl_exec($ch)){
    echo 'File was successfully transferred using SFTP';
  }else{
    echo 'File was unable to be transferred using SFTP';
  }
  
  curl_close ($ch);

 

any advice would be greatly appreciated.

 

Steve

Link to comment
https://forums.phpfreaks.com/topic/131767-upload-textfile-using-curl-sftp/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.