Dylan Jones
Dylan Jones

Reputation: 301

FTP Api? PHP Server to server uploading

I know that there is a ton of PHP FTP functions, but I have tried so many times in the past to get the basics to work. Can connect, but usually run into problems with listing directories, etc.

Is there a service, or API where I can tell it download this folder (or zip) then upload & unzip to this server? (just transfer would work too).

PHP has functions for this, but I can't get it to work - using Laravel framework with the SFTP bundle with PagodaBox hosting, and it seems Pagoda doesn't even have the php FTP module installed.

Is there any way to do this without PHP or some remote service?

Or will I need to get second server that has right setup for FTP PHP functions, then just create my own little api? Any good hosting companies that have all the right setup out of the box?

Update

More info on what I am trying to do:

I am creating a service where people create websites then can download that website in a zip file (HTML files, etc) but I would like to offer my clients a way to use FTP to automatically upload it for them.

Upvotes: 1

Views: 1393

Answers (2)

halfer
halfer

Reputation: 20430

(Posted answer on behalf of the question author).

This is solved - I had to edit boxfile in Pagodabox for PHP extension.

Upvotes: 0

Prasanth
Prasanth

Reputation: 5258

You can do this using cURL.

Here is a sample code:

<?php
if(!function_exists('curl_init'))
    die('cURL isn\'t available too!');

$file = "toUp.zip";
$ch = curl_init();
$fp = fopen($file, 'r');

curl_setopt($ch, CURLOPT_URL, 'ftp://username:[email protected]/public_html/'.$file);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));

curl_exec($ch);
$err_no = curl_errno($ch);
curl_close($ch);
fclose($fp);

if($err_no == 0){
    echo 'FTP Transfer complete.';
}else{
    echo 'FTP Transfer error: '.$err_no;
    echo '. See http://curl.haxx.se/libcurl/c/libcurl-errors.html';
}
?>

Upvotes: 1

Related Questions