Hi All,

I have a script that works fine for transferring files from one server to another when I use HTTP protocol. (When I use a test site that is.)

Here is the script, working on test site with HTTP:

// Navn på faktura der skal hentes      
        $pdf_faktura_navn = 'Microsoft_sporgeskema.pdf';

        // Url der skal hentes fra  http://mail.site.dk/term/pdffaktura/134/1347074.PDF
        // LIVE FTP SITE
        $url    = 'ftp://mail.site.dk/term/pdffaktura/134/1347074.PDF';

        // TEST HTTP SITE
        //$url  = 'http://www.testsite.dk/'.$pdf_faktura_navn.''; // Works with HTTP

        // Definer sti + navn til/på faktura filen
        // LOCAL FOLDER FOR THE HTTP TEST
        //$path     =  'downloads/'.$pdf_faktura_navn.''; 

        // LIVE FOLDER FOR FTP
        $path   = '/one/two/dev.site.dk/docs/test_site/downloads/'.$pdf_faktura_navn.'';

         // Åben mappen hvor filen skal skrives til
        $fp     = fopen($path, 'w');

        // CURL start + options
        $ch     = curl_init($url);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        //curl_setopt($ch, CURLOPT_PORT, 21);

        // Tjek resultat - Action afhængig af succes eller fejl
        if( $data   = curl_exec($ch) )
        {
            $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);

            if( $info == 404 )
            {
                echo '<p>Return code: ' . $info . '.</p><br />';
                echo '<p>Den valgte fil eksisterer ikke.</p><br />';
            }
            else
            {
                echo '<p>Forbundet til server</p><br />';
                echo '<p>Return code: ' . $info . '.</p><br />';
                //header('Content-type: application/pdf');
                //header('location: downloads/'.$pdf_faktura_navn.'');
                //exit();
                echo '<p>Filen er hentet fra <b>'.$url.'</b></p><br />';
                echo '<p>Den valgte fil (Faktura) - Kan ses via linket her: <b><a href="downloads/'.$pdf_faktura_navn.'">LINK TIL FAKTURA...</a></b></p>';
            }   
        }
        else
        {
            echo '<p>Der skete en fejl da vi forsøgte at hente fakturaen.</p>';   
        }    

        // CURL slut
        curl_close($ch);
        fclose($fp);

The site I need to retrieve the PDF's from is set up as a FTP site - My problem is that I am new to Curl and this entire ftp thing, so any help and hints are highly appreciated. - How do I connect using Curl and can it be used for that?

Regards
/Klemme

If this is the url I need to connect to, is this then correct when using FTP

$url    = 'ftp.mail.site.dk/terminal/pdffaktura/134/1347074.PDF';

// AND for the curl part - For accessing with my credentials:
$ch     = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_USERPWD, "ABC\Admin:12345678");

Or am I doing something wrong in these steps?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.