Jump to content

Download a file with Curl stopped working when the supplier update their security. I need help in downloading the file.


Recommended Posts

I was using:


$local_file = 'cit_order_download'. date('mdY_hia') .'.co';
$server_file = 'CCDATA.TXT';
$curl = curl_init();
$fh   = fopen($local_file , 'w');
curl_setopt($curl, CURLOPT_URL, 'ftp://tf.ftpuat.removed.com/Outbox/' . $server_file);
curl_setopt($curl, CURLOPT_USERPWD, "removed");
curl_setopt($curl, CURLOPT_PORT, 22);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);

fwrite($fh, $result);

fclose($fh);
curl_close($curl)

I installed phpseclib but I can't make it work.

I tried:

$remoteDir = "/Outbox/";
$localDir = "./";

$connection = ssh2_connect($url);
if (!ssh2_auth_password($connection, $username, $password)) throw new Exception('Unable to connect.');

if(!$stream = ssh2_sftp($connection)){
  die("Unable to create stream");
}

if(!$dir = opendir("ssh2.sftp://{$stream}/{$remoteDir}")){
  die("Could not open dir");
}

$file = 'ccdata.txt';

$remote = @fopen("ssh2.sftp://{$stream}/{$remoteDir}{$file}","r");
 
  
$local = @fopen($localDir . $localFile, "w");


  $read = 0;
  $filesize = filesize("ssh2.sftp://{$stream}/{$remoteDir}{$file}");
  while ($read < $filesize && ($buffer = fread($remote, $filesize - $read))){
    $read += strlen($buffer);
    if(fwrite($local, $buffer) === false){
      echo "Unable to write to local file: $file\n";
    }

  fclose($local);
  fclose($remote);
}

but the filesize stat throws an error that I can't seem to get around. I use php because I download the file and read it and update our erp system with the data in the file.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.