Title: FTP Create Upload Path doesn&#039;t work
Last modified: August 30, 2016

---

# FTP Create Upload Path doesn't work

 *  Resolved [lobsterdog](https://wordpress.org/support/users/lobsterdog/)
 * (@lobsterdog)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/)
 * When trying to use Create Upload Path under FTP mode I get this error on the 
   server: [INFO] Can’t change directory to /example/: No such file or directory
 * I’ve tried to play with settings, passive, active but no luck.
 * Any suggestions?
 * Thank you
 * [https://wordpress.org/plugins/wp-file-upload/](https://wordpress.org/plugins/wp-file-upload/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [lobsterdog](https://wordpress.org/support/users/lobsterdog/)
 * (@lobsterdog)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304145)
 * Ok. So even when I use no path and select OFF for Create Upload Path I get this
   error: [INFO] Can’t change directory to /npp.6.7.9.2.Installer.exe: No such file
   or directory
 * So the FTP part of the plugin is not working at all.
 * 🙁
 *  Thread Starter [lobsterdog](https://wordpress.org/support/users/lobsterdog/)
 * (@lobsterdog)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304146)
 * The error I get on the browser for both times: Upload failed! Error occured while
   moving temporary file. Please contact administrator.
 *  Thread Starter [lobsterdog](https://wordpress.org/support/users/lobsterdog/)
 * (@lobsterdog)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304148)
 * Upload failed! Error occured while moving temporary file. Please contact administrator.
   
   Failed upload path: ftp://[server]:71/npp.6.7.9.2.Installer.exe Warning: fileperms():
   stat failed for ftp://[server]:71 in /var/www/html/wp-content/plugins/wp-file-
   upload/lib/wfu_io.php on line 51 Warning: ftp_connect(): php_network_getaddresses:
   getaddrinfo failed: Name or service not known in /var/www/html/wp-content/plugins/
   wp-file-upload/lib/wfu_io.php on line 69 Warning: ftp_login() expects parameter
   1 to be resource, boolean given in /var/www/html/wp-content/plugins/wp-file-upload/
   lib/wfu_io.php on line 70 Warning: ftp_quit() expects parameter 1 to be resource,
   boolean given in /var/www/html/wp-content/plugins/wp-file-upload/lib/wfu_io.php
   on line 102 Error. Invalid ftp information. Check ‘ftpinfo’ attribute.
 *  Thread Starter [lobsterdog](https://wordpress.org/support/users/lobsterdog/)
 * (@lobsterdog)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304168)
 * I fixed my own problem.
    All you need to do: 1. Replace the wp-file-upload/lib/
   wfu_io.php file with the code I attached 2. No matter what, you have to add :
   21 (or the ftp port you use if different of the default 21) Like: username:password@serveraddress:
   21 on your FTP credentials 3. Enable Passive Mode
 * Tha’s All!
 * Code:
 *     ```
       <?php
   
       function wfu_create_directory($path, $method, $ftpdata) {
       	$ret_message = "";
       	if ( $method == "" || $method == "normal" ) {
       		mkdir($path, 0777, true);
       	}
       	else if ( $method == "ftp" && $ftpdata != "" ) {
       		$ftpdata_flat =  str_replace(array('\:', '\@'), array('\_', '\_'), $ftpdata);
       		$pos1 = strpos($ftpdata_flat, ":");
       		$pos2 = strpos($ftpdata_flat, "@");
       		if ( $pos1 && $pos2 && $pos2 > $pos1 ) {
       			$ftp_username = substr($ftpdata, 0, $pos1);
       			$ftp_password = substr($ftpdata, $pos1 + 1, $pos2 - $pos1 - 1);
       			list($ftp_host, $ftp_port) = explode(":", substr($ftpdata, $pos2 + 1));
       			$conn_id = ftp_connect($ftp_host,$ftp_port);
       			$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
       			if ( $conn_id && $login_result ) {
       				$flat_host = preg_replace("/^(.*\.)?([^.]*\..*)$/", "$2", $ftp_host);
       				echo $flat_host." ";
       				$pos1 = strpos($path, $flat_host);
       				echo $pos1." ";
       				if ( $pos1 ) {
       					echo $path." ";
       					$path = substr($path, $pos1 + strlen($flat_host.":".$ftp_port));
       					echo $path;
       					ftp_mkdir($conn_id, $path);
       					ftp_chmod($conn_id, 493, $path);
       				}
       				else {
       					$ret_message = WFU_ERROR_ADMIN_FTPDIR_RESOLVE;
       				}
       			}
       			else {
       				$ret_message = WFU_ERROR_ADMIN_FTPINFO_INVALID;
       			}
       			ftp_quit($conn_id);
       		}
       		else {
       			$ret_message = WFU_ERROR_ADMIN_FTPINFO_EXTRACT;
       		}
       	}
       	else {
       		$ret_message = WFU_ERROR_ADMIN_FTPINFO_INVALID;
       	}
       	return $ret_message;
       }
   
       function wfu_upload_file($source, $target, $method, $ftpdata, $passive, $fileperms) {
       	$ret_array = "";
       	$ret_array["uploaded"] = false;
       	$ret_array["admin_message"] = "";
       	$ret_message = "";
       	$target_perms = substr(sprintf('%o', fileperms(dirname($target))), -4);
       	$target_perms = octdec($target_perms);
       	$target_perms = (int)$target_perms;
       	if ( $method == "" || $method == "normal" ) {
       		$ret_array["uploaded"] = move_uploaded_file($source, $target);
       		if ( !$ret_array["uploaded"] && !is_writable(dirname($target)) ) {
       			$ret_message = WFU_ERROR_ADMIN_DIR_PERMISSION;
       		}
       	}
       	elseif ( $method == "ftp" &&  $ftpdata != "" ) {
       		$result = false;
       		$ftpdata_flat =  str_replace(array('\:', '\@'), array('\_', '\_'), $ftpdata);
       		$pos1 = strpos($ftpdata_flat, ":");
       		$pos2 = strpos($ftpdata_flat, "@");
       		if ( $pos1 && $pos2 && $pos2 > $pos1 ) {
       			$ftp_username = substr($ftpdata, 0, $pos1);
       			$ftp_password = substr($ftpdata, $pos1 + 1, $pos2 - $pos1 - 1);
       			list($ftp_host, $ftp_port) = explode(":", substr($ftpdata, $pos2 + 1));
       			$conn_id = ftp_connect($ftp_host,$ftp_port);
       			$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
       			if ( $conn_id && $login_result ) {
       				$flat_host = preg_replace("/^(.*\.)?([^.]*\..*)$/", "$2", $ftp_host);
       				$pos1 = strpos($target, $flat_host);
       				if ( $pos1 ) {
       					if ( $passive == "true" ) ftp_pasv($conn_id, true);
       //					$temp_fname = tempnam(dirname($target), "tmp");
       //					move_uploaded_file($source, $temp_fname);
       					$target = substr($target, $pos1 + strlen($flat_host.":".$ftp_port));
       //					ftp_chmod($conn_id, 0755, dirname($target));
       					$ret_array["uploaded"] = ftp_put($conn_id, $target, $source, FTP_BINARY);
       					//apply user-defined permissions to file
       					$fileperms = trim($fileperms);
       					if ( strlen($fileperms) == 4 && sprintf("%04o", octdec($fileperms)) == $fileperms ) {
       						$fileperms = octdec($fileperms);
       						$fileperms = (int)$fileperms;
       						ftp_chmod($conn_id, $fileperms, $target);
       					}
       //					ftp_chmod($conn_id, 0755, $target);
       //					ftp_chmod($conn_id, $target_perms, dirname($target));
       					unlink($source);
       					if ( !$ret_array["uploaded"] ) {
       						$ret_message = WFU_ERROR_ADMIN_DIR_PERMISSION;
       					}
       				}
       				else {
       					$ret_message = WFU_ERROR_ADMIN_FTPFILE_RESOLVE;
       				}
       			}
       			else {
       				$ret_message = WFU_ERROR_ADMIN_FTPINFO_INVALID;
       			}
       			ftp_quit($conn_id);
       		}
       		else {
       			$ret_message = WFU_ERROR_ADMIN_FTPINFO_EXTRACT.$ftpdata_flat;
       		}
       	}
       	else {
       		$ret_message = WFU_ERROR_ADMIN_FTPINFO_INVALID;
       	}
   
       	$ret_array["admin_message"] = $ret_message;
       	return $ret_array;
       }
   
       ?>
       ```
   
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304298)
 * Didn’t know that declaration of port number is so important.
 * Thanks for informing me about your problem and the soltion of course.
 * Nickolas
 *  Thread Starter [lobsterdog](https://wordpress.org/support/users/lobsterdog/)
 * (@lobsterdog)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304301)
 * Well, it wasn’t. But because I needed a different port, I implemented on my modification.
   
   It would be nice if you copy this code into the next versions so I wouldn’t need
   to re-do it. 😉
 * Thank you,
 *  Thread Starter [lobsterdog](https://wordpress.org/support/users/lobsterdog/)
 * (@lobsterdog)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304395)
 * Nickolas,
    Just came here to say thank you. I updated the plugin yesterday “by
   mistake” and than I thought: shi*** I will have to implement the port thing again.
   But I realized you had inserted my code on the update.
 * Thank you so much,
    Igor
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304403)
 * Ok you are welcome
 * Nickolas

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘FTP Create Upload Path doesn't work’ is closed to new replies.

 * ![](https://ps.w.org/wp-file-upload/assets/icon-256x256.png?rev=3252590)
 * [Iptanus File Upload](https://wordpress.org/plugins/wp-file-upload/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-file-upload/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-file-upload/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-file-upload/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-file-upload/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-file-upload/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [nickboss](https://wordpress.org/support/users/nickboss/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/ftp-create-upload-path-doesnt-work/#post-6304403)
 * Status: resolved