Strange ftp_put() path problem ... can anyone have a look?

Hi guys

Well, I tried for the first time ftp_put in a new server, and while the script worked perfectly in a diffrent server, is not working in this one. Here is the error that I’m getting.

Warning: ftp_put() [function.ftp-put]: Rename/move failure: No such file or directory in /home/user/public_html/folder/myfile.php on line xx

For ftp_put, I am using

ftp_put($conn_id,$destination_file,$file,FTP_BINARY)

where destination file is

/home/user/public_html/folder1/folder2/myfile2upload.ext

Any hints here? Thanks for ur time.
Best

What’s the ftp root directory? It’s unusual for it to be the actual server root directory so it’s probably trying to upload to /home/user/public_html/home/user/public_html/folder1/folder2/

Try using /folder1/folder2/myfile2upload.ext as the destination file (presuming /home/user/public_html is where the ftp root is).

Thanks Mark. But nope, I’m still getting the same error. In fact I have checked the destination file in various way, but getting the same result everyway.

My root directory is /, then the particular site where I am having the problem is located at /home/user/public_html/. The php file is located at /home/user/public_html/folder1/ and the folder where I am trying to upload the files are located one level deeper, that is at /home/user/public_html/folder1/folder2/

I am really lost here … tried everything, and it’s almost 24 hours that I am trying to solved this issue … :injured: :injured: :injured:

Here is the full code that i’m using …


$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to Kigoobe server");
$login_result = ftp_login($conn_id, $p_login, $p_password) or die("Couldn't log in to Kigoobe server");
$destination_path = "/home/user/public_html/folder1/folder2/";
$destination_file = $destination_path.$filename;
$file = $myFile['tmp_name'];
if(ftp_put($conn_id,$destination_file,$file,FTP_BINARY)) {
// do something ...
} else {
print 'Upload failed';
}
ftp_close($conn_id);
//header('Location: confirm-page.php');

In case I am doing something wrong …

well, I think I have found the problem. It’s not about the destination file, it’s happening as I am not specifying the full path of the source tmp folder. But, where’s the tmp folder !!!

So, after a lot of googling, and following some tips, I found that may be I should direct my uploaded file to upload_tmp_dir. I then changed the php.ini and used /tmp as the destination for upload_tmp_dir.

Now, everything should work as I have used destination file as

'/home/user/public_html/folder1/folder2/'.$filename

and source file as

'/tmp/temp_name'

But even now, this is not working. I am again getting the same error as before

Warning: ftp_put() [function.ftp-put]: Rename/move failure: No such file or directory

Thinking, what can I do next !!!

Thanks for any help … It’s two days now that I am trying to solve this issue … :injured:

well, it’s solved :slight_smile:

Hey how did you solve this?

I forgot. In fact, today I was needing the same again, and I couldn’t make out what I did last time. I will try again, and if I find a solution, I will post it here. Besides, check the permission of your folder, that may sometimes cause this problem.

Logically, this can be either a permission or a path problem as there’s nothing more in this function.

I figure it out, i found out that this new server is different from my other server, so It was the path that are incorrect… :smiley:

OK, solved. So, I am making a recap if someone else faces a similar situation and arrive here googling or using SP’s search.

Checklist for a file upload using ftp_put()

1. Check the form enctype. I used multipart/form-data to upload word, excel or jpegs using ftp_put()

2. Check the permission of your folder. Unless you have PHPSuExec installed, you change permission of the destination folder to 777

3. See the path of your destination, as that’s what creates the problem most of the time. Incase we use ftp_put() with basename($fileName); ($fileName is any file name of your choice + the valid extension for the file uploaded) then the files are uploaded to /home/user/ folder.

So, in case you want to upload your files to a sub folder called dynamicDocuments situated at the same level where your index.php file is, you have to use the path as

$destination_file = 'public_html/dynamicDocuments/'.basename($fileName);

and that solves the issue.

HTH someone. :slight_smile:

Credit : Serra of HostGator who helped me to understand the problem. Thanks Serra. :slight_smile:

Either you give the full path of the file or you can change your current working directory with the help of ftp_chdir().

different server has different default name of your document root, incase you need to use the

$_SERVER['DOCUMENT_ROOT']

this syntax will determine your full path, and check the following:

Destination : of course the file where you want to upload or put the file.
Source :

  1. if youre uploading using $_FILES or using the file type control then the source must be the $_FILES[‘filecontrol_name’][‘tmp’], now remember that the ‘tmp’ or ‘temp’ you must specify it or you must know the exact location of it.

  2. ‘temp’ or ‘tmp’ must have permission to write, and also the destination folder.


//connection_id_resources (this is the result of the ftp_login )

ftp_put( connection_id_resources, destination, source, FTP_BINARY o FTP_ASCII )

why use ftp function to upload file, and not ordinary ‘move_upload_file’
my reason is that when you use the basic file upload the owner of the file is apache, not the real user login name, for instance your login username is ‘john’ then when you upload ‘dummy.txt’ then dummy.txt owned by apache, which is somehow a treat to the hackers or want to exploit your website.

but using the ftp function to upload then ‘dummy.txt’ is owned by ‘john’…

I dont know about the others but that is my reason… anyway hope you understand and gain knowledge… happy coding… :slight_smile:

What do you use to transfer a file from one server to another? Does the move_uploaded_file() function work on such a case?

because the file owner is not the owner…