# Php FTP upload not working

**URL:** <https://www.phphelp.com/t/php-ftp-upload-not-working/34976>\
**Category:** General PHP Help\
**Created:** [August 25, 2022, 8:10pm UTC](https://www.phphelp.com/t/php-ftp-upload-not-working/34976 "2022-08-25T20:10:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![j84](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@j84](https://www.phphelp.com/u/j84)\
**Post date:** [August 25, 2022, 8:10pm UTC](https://www.phphelp.com/t/php-ftp-upload-not-working/34976/1 "2022-08-25T20:10:58Z")

</div>

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.

```auto

$rowFTPHost = "MYIP";
$rowFTPUser = "MYUSERNAME@mydomain.se";
$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)

---

<div class="post-metadata">

**Author:** ![j84](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@j84](https://www.phphelp.com/u/j84)\
**Post date:** [August 26, 2022, 7:40am UTC](https://www.phphelp.com/t/php-ftp-upload-not-working/34976/2 "2022-08-26T07:40:29Z")

</div>

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