How to upload large file(s) on FTP server

2019-07-02 11:20发布

问题:

$ftp_server = 'ftp.abc.com';
$remote_file = "myvideo.avi";  // file size 210MB
$file = "myvideo.avi";        // file size 210MB
$conn_id = ftp_connect($ftp_server);  // set up basic connection

// login with username and password
$login_result = ftp_login($conn_id, 'faraz@abc.com', 'password');

ftp_pasv($conn_id, true); // turn passive mode on
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
     echo "successfully uploaded $file\n";
} else {
     echo "There was a problem while uploading $file\n";
}
    // close the connection
    ftp_close($conn_id);

i already edit php.in for
upload_max_filesize = 1024M

above snippet working on all types of file(s) upload,
but when am trying to upload a large size file then it upload on server but size varies after uploading.
A video file size-210MB on local-machine
but after upload, it displayed file size 328KB on FTP-server.
i have no idea where do i check, if someone has suggestion then i appreciates

回答1:

Use FTP_BINARY instead of FTP_ASCII. The latter might stop at the first NUL byte.

Besides that, there is no good reason to use ascii mode nowadays, even for ascii files. The only case where it's important if you have cgi scripts containing a shebang line that have windows linebreaks locally.