PHP FTP Error - Access Denied

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

PHP FTP Error - Access Denied

Post by koolsamule »

Hi Chaps,

I'm tyring to make a PHP / FTP Application, where users can view/download/upload files in a given FTP site.

I can connect to the FTP server, login using the credentials, but when I try to upload, or create a directory, I get:
Warning: ftp_mkdir() [function.ftp-mkdir]: www: Access is denied. in C:\webserver\Apache2\htdocs\ftp\test.php on line 16
Line 16:

Code: Select all

if (ftp_mkdir($conn_id, $dir)) {
 echo "successfully created $dir\n";
} else {
 echo "There was a problem while creating $dir\n";
}
As before, the credentials are correct, but I think there is a security issue somewhere what is blocking access.

If anyone has any ideas what this could be, please share the wealth!

Cheers
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: PHP FTP Error - Access Denied

Post by infolock »

Well, you will want to check the group permissions you are applying to the directory where they can upload to.

Does the User who is logging in belong to that Group?

Does the chmod of the directory have rwx access for that Group?

Have you tried echoing out just what directory path you are trying to create a new directory in?
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

Re: PHP FTP Error - Access Denied

Post by koolsamule »

Hi, thanks for the reply, please excuse my lack of knowledge on this:
Does the User who is logging in belong to that Group?
- I've added an Internet Guest Account (IUSER) to the FTP directory with full access
Does the chmod of the directory have rwx access for that Group?
- Think so, how can I check for sure?

This is my code so far (want to create a directory called TEST):

Code: Select all

<?php
 
$ftpServer = "www.domain.co.uk";
$ftpUser = "username";
$ftpPass = "password";
 
set_time_limit(160);
 
$conn = @ftp_connect($ftpServer)
or die("Couldn't connect to FTP server");
 
$login = @ftp_login($conn, $ftpUser, $ftpPass)
or die("Login credentials were rejected");
 
set_time_limit(160);
 
$conn = @ftp_connect($ftpServer)
or die("Couldn't connect to FTP server");
 
$login = @ftp_login($conn, $ftpUser, $ftpPass)
or die("Login credentials were rejected");
 
$workingDir = ftp_pwd($conn);
echo "You are in the directory: $workingDir<br><br>";
 
ftp_mkdir($conn, 'TEST');
 
echo "<br><br>Files for directory: $workingDir<br><br>";
 
$fList = @ftp_nlist($conn, $workingDir);
 
if(is_array($fList))
{
for($i = 0; $i < sizeof($fList); $i++)
{
echo $fList[$i] . "<br>";
}
}
else
{
echo "$workingDir contains no files.";
}
 
ftp_quit($conn);
 
?>
johnsoce
Forum Newbie
Posts: 1
Joined: Thu Mar 04, 2010 11:08 am

Re: PHP FTP Error - Access Denied

Post by johnsoce »

I thought I would just piggy-back off this thread.

I too am trying to FTP files to an online file storage system through PHP, and I've determined that my hosting company (GoDaddy) does not allow this type of FTP access. (They only allow access from ftp client programs or through web browsers).

Do any of you have suggestions for other online file storage systems or hosting companies that allow FTP through PHP? I'm starting to determine there must not be many out there through the research I've already done. I figure someone in this forum has a good recommendation from past experiences.

Regards,
Chris
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

Re: PHP FTP Error - Access Denied

Post by koolsamule »

Follow up:
I have just tested creating a new directory using CuteFTP Pro and I got an error:
Request denied.
Please verify that the file or folder exists and that you have the necessary permissions on the server to perform the requested operation.
Do you know what I should look for to get both FTP Client and my Web App to work correctly?
koolsamule
Forum Contributor
Posts: 130
Joined: Fri Sep 25, 2009 10:03 am

Re: PHP FTP Error - Access Denied

Post by koolsamule »

Looks like I had my FTP path wrong, it was trying to create a directory on the root, rather than in one of the accessible directories within the FTP site. Now sorted!
Post Reply