0

I am trying to transfer file from one server to another using FTP but I can't see the mistake in my code. It only shows message from ELSE.

Did I made mistake with FTP connection or with path of files?

/* Remote File Name and Path */
$remote_file = "output/5e18704b91013.mp4";

/* FTP Account (Remote Server) */
$ftp_host = '*****'; /* host */
$ftp_user_name = '******'; /* username */
$ftp_user_pass = '****'; /* password */

/* File and path to send to remote FTP server */
$local_file = "video.mp4";

/* Connect using basic FTP */
$connect_it = ftp_connect( $ftp_host );


/* Login to FTP */
echo $login_result = ftp_login( $connect_it, $ftp_user_name, $ftp_user_pass );

/* Send $local_file to FTP */
if ( ftp_get( $connect_it, $remote_file, $local_file, FTP_BINARY ) ) {
    echo "WOOT! Successfully transfer $local_file\n";
}
else {
    echo "Doh! There was a problem\n";
}

/* Close the connection */
ftp_close( $connect_it );
Alexander
  • 51
  • 2
  • 8
  • Do you have [error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) on? what error message(s) do you get? – jibsteroos Jan 10 '20 at 13:03
  • I am getting this error: Warning: ftp_get(): Can't open video.mp4: No such file or directory in C:\home\site\wwwroot\test.php on line 39 – Alexander Jan 10 '20 at 13:07
  • 1
    do you miss a slash? _www\root_ ? – Sfili_81 Jan 10 '20 at 13:10
  • I've used FTP in PHP twice. Both times, I had massive issues with firewall rules. The ohly error I got was "file not found". Try completely opening the firewall. If it works, you know it is a firewall rule. Then, lock it back down and figure out what you need to open. – kainaw Jan 10 '20 at 13:13
  • 1
    `ftp_get` is for retrieving, not sending.. maybe you meant https://www.php.net/manual/en/function.ftp-put.php? – user3783243 Jan 10 '20 at 13:16
  • @Sfili_81 I dont miss \ between www and root. I am using free GearHost. That is a windows server where I put exe file and one php file to run online video compression when I needed. But don't know how to transfer that compressed file to my real server. – Alexander Jan 10 '20 at 13:18
  • @user3783243 now I get this error ftp_put(): Can't open that file: No such file or directory in C:\home\site\wwwroot\test.php on line 39 – Alexander Jan 10 '20 at 13:19
  • 1
    The error is clear, your video file can't be open, you have to do some debug and discover why it can't be opened. – Sfili_81 Jan 10 '20 at 13:20

0 Answers0