Closed ethanpil closed 9 years ago
Some additional debugging info:
Curl is installed on my PHP.
I added this code
$data = curl_exec($ch);
$log_msg .= $this->log_it('DATA IS '.$data,false); //Added this
curl_close($ch);
The log file is not showing any of the $data
so it seems I am pulling a blank from bitbucket... any ideas?
It is a problem with curl on my server. Here is alternate code that worked for me, switching to file_get_contents()
function load_files(){
$ftp = $this->get_ftpdata();
$log_msg = '';
$log_msg .= $this->log_it('Connecting branch '.$ftp['branch_name'].' to '.$ftp['ftp_host'].$ftp['ftp_path'],false);
// Makes a nice path
if(substr($ftp['ftp_path'],0,1)!='/') $ftp['ftp_path'] = '/'.$ftp['ftp_path'];
if(substr($ftp['ftp_path'], strlen($ftp['ftp_path'])-1,1)!='/') $ftp['ftp_path'] = $ftp['ftp_path'].'/';
$conn_id = ftp_connect($ftp['ftp_host']);
if(!@ftp_login($conn_id, $ftp['ftp_user'], $ftp['ftp_pass'])){
$this->error('error: Connection failed!');
}else{
foreach($this->commits as $commit) {
$node = $commit->node;
$time = $commit->timestamp;
foreach($commit->files as $file) {
if ($file->type=="removed") {
// TODO: Check if file exists
if(@ftp_delete($conn_id, $ftp['ftp_path'].$file->file)) {
$log_msg .= $this->log_it('Removed '.$ftp['ftp_path'].$file->file,false);
}
}else{
$url = "https://api.bitbucket.org/1.0/repositories".$this->repo->absolute_url."raw/".$node."/".$file->file;
$dirname = dirname($file->file);
$chdir = @ftp_chdir($conn_id, $ftp['ftp_path'].$dirname);
if($chdir == false){
if($this->make_directory($conn_id, $ftp['ftp_path'].$dirname)){
$log_msg .= $this->log_it('Created new directory '.$dirname,false);
} else {
$log_msg .= $this->log_it('Error: failed to create new directory '.$dirname,false);
}
}
$cred = sprintf( 'Authorization: Basic %s',
base64_encode($this->bitbucket['username'] . ":" . $this->bitbucket['password'])
);
$opts = array(
'http' => array(
'method' => 'GET',
'header' => $cred
)
);
$ctx = stream_context_create( $opts );
$data = file_get_contents( $url, false, $ctx );
$temp = tmpfile();
fwrite($temp, $data);
fseek($temp, 0);
ftp_fput($conn_id, $ftp['ftp_path'].$file->file, $temp, FTP_BINARY);
fclose($temp);
$log_msg .= $this->log_it('Uploaded: '.$ftp['ftp_path'].$file->file,false);
}
}
}
The correct file is uploaded to its destination on the deploy server, but it always has 0 bytes. I am on windows 2008 server with xampp.
I have the same problem with the original code here: https://bitbucket.org/sibbl/bitbucket-ftp-deployment/overview
I can write files with file_put_contents so its not a permissions issue.