Skip to content

Instantly share code, notes, and snippets.

@ZZromanZZ
Created July 23, 2013 18:38
Show Gist options
  • Save ZZromanZZ/6064967 to your computer and use it in GitHub Desktop.
Save ZZromanZZ/6064967 to your computer and use it in GitHub Desktop.
curl get ftpAuth file
<?php
function saveFtpFile( $targetFile = null, $sourceFile = null, $ftpuser = null, $ftppassword = null ){
// function settings
$timeout = 50;
$fileOpen = 'w+';
$curl = curl_init();
$file = fopen (dirname(__FILE__) . '/'.$targetFile, $fileOpen);
curl_setopt($curl, CURLOPT_URL, $sourceFile);
curl_setopt($curl, CURLOPT_USERPWD, $ftpuser.':'.$ftppassword);
// curl settings
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_FILE, $file);
$result = curl_exec($curl);
$info = curl_getinfo($curl);
curl_close($curl);
fclose($file);
return $result;
}
//saveFtpFile("", "", "", "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment