Ftp_Put Is Corrupting My Movies After Transfer, Is It Wrong

ftp_put is corrupting my movies after transfer, is it wrong?

You're trying to upload something other than a text-based file while using

(ftp_put($conn_id, $remote_file, $localfile, FTP_ASCII))

You should be using FTP_BINARY instead of FTP_ASCII since movies (and images) are binary files.

File corrupted after downloading it with php (ftp)

Try switching the FTP mode to binary, i.e. replace this line:

if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII)) {

with this:

if (ftp_get($ftp_conn, $local_file, $server_file, FTP_BINARY)) {

More information here

Why the image is getting corrupted uploaded to the FTP server using PHP?

You should set the mode with ftp_put to be FTP_BINARY:

ftp_put($conn_id, $remote_file, $file, FTP_BINARY); 

This is mandatory since ASCII mode checks whether the line endings differ on client/server (your case, since you are likely on windows and the server runs unix) and tries to convert them (\r\n\n). In BINARY mode files are being sent as is.

Upload a file to FTP using PHP without the file being damaged

Change FTP_ASCII to FTP_BINARY.

Explanation:

FTP_ASCII for plain-text files.
FTP_BINARY for any file type, including plain-text files. E.g. a JPEG file is binary in nature.

Behind the scenes, with FTP_ASCII any encounter of the null character (ordinal 0) will throw off your results on binary files. I think.

In any event FTP_BINARY should resolve your issue.

PHP ftp_put fails

Most typical cause of problems with ftp_put (or any other transfer command like ftp_get, ftp_nlist, ftp_rawlist, ftp_mlsd) is that PHP defaults to the active mode. And in 99% cases, one has to switch to the passive mode, to make the transfer working. Use the ftp_pasv function.

$connect = ftp_connect($ftp) or die("Unable to connect to host");
ftp_login($connect, $username, $pwd) or die("Authorization failed");
// turn passive mode on
ftp_pasv($connect, true) or die("Unable switch to passive mode");

The ftp_pasv must be called after ftp_login. Calling it before has no effect.

See also:

  • PHP ftp_put fails with "Warning: ftp_put (): PORT command successful"
  • my article on the active and passive FTP connection modes.

ZIP Archive Becomes Corrupt Only After Upload to FTP From PHP

I've tested your code on my Ubuntu system and it worked without problems.

This is probably an FTP server problem; you should try to upload the file on another FTP server.



Related Topics



Leave a reply



Submit