Php FTP upload not working

Hi!
I have a php script that creates 2 folder on an external server → ftp account → in /public_html/FOLDERNAME and uploads a php file to a folder. It works well on local server.
Its a cms website installation file.

Then I tried it on an exnternal ftp server I have. It creates the folders but error when upload.

It timeouts everytime it tries to upload the file. I tryed ftp_pasv($ftp_conn, true);
Then it goes fast again but no files is uploaded still. Anyone have any idea what Im doing wrong?

What I want to achieve:

  1. Connect to external ftp
  2. Create DIR $strFolder (Name comes from a form input)
  3. Create DIR $strFolder/inc
  4. Upload install.php from ‘/msite/lang_sv.php’ to ‘$strFolder/inc/lang_sv.php’
  5. Upload install.php from ‘/msite/pre.php’ to ‘$strFolder/inc/pre.php’
  6. Close Ftp connection.

$rowFTPHost = "MYIP";
$rowFTPUser = "[email protected]";
$rowFTPPass = "MYPASSWORD"; 

    // connect and login to FTP server
    $ftp_server = $rowFTPHost;
    $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
    $login = ftp_login($ftp_conn, $rowFTPUser, $rowFTPPass);
    //ftp_pasv($ftp_conn, true);

    // create folder
    if (ftp_mkdir($ftp_conn, $strFolder))
      {
      echo "Successfully created folder: $strFolder<br>";
      }
    else
      {
      echo "Error creating folder: $strFolder<br>";
      }

      $strFolderINC = $strFolder."/inc";

    // create folder inc
    if (ftp_mkdir($ftp_conn, $strFolderINC))
      {
      echo "Successfully created subfolder: $strFolderINC<br>";
      }
    else
      {
      echo "Error creating subfolder: $strFolderINC<br>";
      }

    $INSTALLfile = '/msite/install.php';
    $INSTALLremote_file = $strFolder.'/install.php';

		// upload file
		if (ftp_put($ftp_conn, $INSTALLremote_file, $INSTALLfile, FTP_ASCII))
		  {
		  echo "Successfully uploaded $INSTALLfile<br>";
		  }
		else
		  {
		  echo "Error uploading $INSTALLfile<br>";
		  }

		$SVfile = 'msite/lang_sv.php';
		$SVremote_file = $strFolder.'/inc/lang_sv.php';
		  
		 // upload file lang_sv
		if (ftp_put($ftp_conn, $SVremote_file, $SVfile, FTP_ASCII))
		  {
		  echo "Successfully uploaded $SVfile<br>";
		  }
		else
		  {
		  echo "Error uploading $SVfile<br>";
		  }

		$PREfile = 'msite/pre.php';
		$PREremote_file = $strFolder.'/inc/pre.php';
		  
		 // upload file pre
		if (ftp_put($ftp_conn, $PREremote_file, $PREfile, FTP_ASCII))
		  {
		  echo "Successfully uploaded $PREfile<br>";
		  }
		else
		  {
		  echo "Error uploading $PREfile<br>";
		  }

Outpouts:

Successfully created folder: mallan8
Successfully created subfolder: mallan8/inc
Error uploading /msite/install.php
Error uploading /msite/lang_sv.php (to: mallan8/inc/lang_sv.php)
Error uploading /msite/pre.php (to: mallan8/inc/pre.php)

It was nothing wrong with my script. it was the file itself that timeout. :upside_down_face:

Sponsor our Newsletter | Privacy Policy | Terms of Service