How to upload file to FTP server using PHP?
<?php $file = '/path/to/file/local'; $remote_file = 'file.remote'; $dir = '/path/to/local/dir'; $ftp_server = 'ftp_server.com'; $ftp_user = 'ftp_user'; $ftp_pass = 'ftp_pass'; $conn_id = ftp_connect($ftp_server); ftp_login($conn_id, $ftp_user, $ftp_pass); //very important ftp_pasv($conn_id, true); ftp_chdir($conn_id, $dir); // upload a file if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) { echo "successfully uploaded $file\n"; } else { echo "There was a problem while uploading $file\n"; } ftp_close($conn_id); ?>
1 Comment
PHP: CURL upload file to FTP/FTPS server | Free Online Tutorials
(June 1, 2020 - 12:55 pm)[…] the past, i posted an article PHP: upload file to FTP server In this article, i use php-ftp module. Now i introduce some method to upload file to FTP/FTPS […]