Download files from ftp server in PHP

前端 未结 3 1031
北海茫月
北海茫月 2020-12-21 06:52

I am using the following format in php code to download files from ftp server.

file_put_contents(
            $filePath.$fileName, file_get_contents(
                


        
相关标签:
3条回答
  • 2020-12-21 07:23
    true == (
    $data = @
        file_get_contents('ftp://username:password@server_name/folder_name/xyz#123.csv')
        )
            ?
        file_put_contents('xyz#123.csv', $data)
            :
        exit;
    
    0 讨论(0)
  • 2020-12-21 07:31

    Use this

    <?php
    
    // define some variables
    $local_file = 'filename.jpg';
    $server_file = 'filename.jpg';
    $ftp_server="www.abc.com";
    $ftp_user_name="username";
    $ftp_user_pass="password";
    
    $conn_id = ftp_connect($ftp_server);
    
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    
    // try to download $server_file and save to $local_file
    if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
        echo "Successfully written to $local_file\n";
    }
    else {
        echo "There was a problem\n";
    }
    // close the connection
    ftp_close($conn_id);
    
    ?>
    
    0 讨论(0)
  • 2020-12-21 07:41

    Try:

    $output = exec("wget -N ftp://username@ftp.server.com/path/to directory/file 2>&1 |grep 'filename w/o extension'|grep -v ftp|grep -v =");
    print $output <to check if file downloaded or not>
    
    0 讨论(0)
提交回复
热议问题