使用php文件大小问题从ftp下载文件

时间:2013-08-29 05:26:47

标签: php ftp download linkshare

我必须使用cron将文件从linkshare服务器下载到我的服务器。

如果文件大小小于2 GB,那么每件事情都是完美的,但如果超过则无法下载。

代码如下:

$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);
    }

提前致谢

2 个答案:

答案 0 :(得分:0)

这是我从链接共享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);
    ?>

我可以在每个文件下载时间之后加载相同的文件。

答案 1 :(得分:0)

尝试点这个链接,它可以帮助你

runtime behavior for the FTP connection