0

I have to download files from linkshare server to my server by using cron.

Every thing is perfect if the file size is less then 2 GB but if exceeds it fails to download.

code is given below

$ftp_server = "***.*******.com";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, '******', '*******');
$ret = ftp_nb_get($conn_id, $localfile, $serverfile, FTP_BINARY);
    while ($ret == FTP_MOREDATA) {
       // Do whatever you want
       echo ".";
       // Continue downloading...
       $ret = ftp_nb_continue($conn_id);
    }
    if ($ret != FTP_FINISHED) {
       echo "There was an error downloading the file...";
       exit(1);
    }

Thanks in advance

Krishna
  • 1,540
  • 2
  • 11
  • 25
  • I suspect that linkshare, ftp, and cron are all irrelevant here. Does your PHP build understand how to write to files larger than 2 GB? Sometimes things need special build options to support large files. – Greg Hewgill Aug 29 '13 at 05:29
  • I am also thinking in this manner. Is there any method by that I can download file in chunks using ftp_get method – Krishna Aug 29 '13 at 05:33

2 Answers2

0

This is my code for get all files from link share ftp

<?php
session_start();
$i = $_REQUEST['i'];
if($i==""){
    $i=0;
    $source_dir=("linkshare");
    $source_folder=dir($source_dir);
    while($files_list=$source_folder->read())
    {   
        if ($files_list!= "." && $files_list!= "..")
        { 
        $pat="linkshare/";
            unlink($pat.$files_list);
        }
        if($files_list!="") 
        {   
            $pat="linkshare/";  
            unlink($pat.$files_list);
        }


    }
}

$destinationnameeeeee = "linkshare/";
    ini_set("max_execution_time",300000000000000000);

    $ftp_server = '';    //ftp server name
    $ftp_user_name = '';    //ftp user name
    $ftp_user_pass = '';    //ftp user password 

    $conn_id = ftp_connect($ftp_server);   
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    $source_folder = ftp_nlist($conn_id, ".");
    foreach($source_folder as $folder_list)
    {
        $folderlisting = explode("_",$folder_list);
        $folders_list[]= $folder_list;           
    }

        $_SESSION['folder_list'] = $folders_list;
        //print_r($folders_list);
        $folder_count=count($_SESSION['folder_list']);

        $cur_folder = $_SESSION['folder_list'][$i];
        $source_file = str_replace('.lmp', '', $_SESSION['folder_list'][$i]);   
        $destination_file = $destinationnameeeeee.str_replace('.lmp', '', $_SESSION['folder_list'][$i]);
        echo $destination_file;

        if ((!$conn_id) || (!$login_result)) 
        {
            echo "<br />FTP connection has failed!";
            echo "<br />Attempted to connect to $ftp_server for user $ftp_user_name";
            exit;
        } 
        else 
        {
            echo "<br />Connected to $ftp_server, for user $ftp_user_name";
        }

    // download the file
    $download = ftp_get($conn_id, $destination_file, $source_file, FTP_BINARY);

    // check download status
    if (!$download) 
    {
        echo "<br />FTP download has failed!";
    } 
    else 
    {
        echo "<br />Downloaded $source_file from $ftp_server as $destination_file";
        //if($i<=$folder_count)
    if($i>=0)
    {   
        $i=$i+1;
    }

    if($i==8)
    {
        exit; // 8 file only now download if you want to extent yourself    
    }

        header("Location:ftpget.php?i=$i");
    }

    ftp_close($conn_id);
    ?>

I can load same file for after every file downloading time.

Padmanathan J
  • 4,614
  • 5
  • 37
  • 75
  • Downloading is working properly at my end but I have issue if the file size is more then 2 GB and and I think you have not addressed that issue in your code.. – Krishna Aug 29 '13 at 06:10
  • file is downloading but process stops when 2 GB download done – Krishna Aug 29 '13 at 06:43
  • for the reason page is over loading so only i can redirect for same page for every file downloading – Padmanathan J Aug 29 '13 at 06:47
0

tryfollowing this link, it could help you

runtime behavior for the FTP connection

mostafa khansa
  • 302
  • 1
  • 6