Ali
Ali

Reputation: 7493

Is it possible to create ftp users and assign them access to select folders using php?

I just needed to know that is it possible in php to create an ftp user, and then create folders on the server and grant ftp access to selected folders for the ftp user created.

Thanks again!

Upvotes: 1

Views: 305

Answers (4)

SlamDunk
SlamDunk

Reputation: 44

The answer is "Yes" if the web process where the script runs allows changes on the FTP settings e.g adding users, group etc. either by native PHP function or additional "Shell script" and it would be "No" if the web process doesn't have access nor privilege to make changes.

Upvotes: 0

Alex Jasmin
Alex Jasmin

Reputation: 39506

There are a few web hosting panels written in PHP that crate ftp accounts among other things so it's definitely possible.

The exact procedure depends completely on the FTP server you use. It may involve creating new Unix user accounts.

This is more an FTP or operating system question than a PHP question though as you need to shell out to do the configuration. As Pekka said you may have more luck asking on Serverfault if you include the details of your setup.

Upvotes: 1

Christopher Tarquini
Christopher Tarquini

Reputation: 11342

No but if I'm not mistaking you could do something like this

Create a shell script (ftp.sh) that's has SUID (make sure it's owned by root and only can be read/written by root) that creates users, sets the permissions, etc

Call the script from php

system("./ftp.sh ".escapeshellarg($newUsername)." ".escapeshellarg($newPassword))

However I'm pretty sure there are more secure/correct ways of doing this. I can definitely see this becoming a security nightmare.

Upvotes: 0

Pekka
Pekka

Reputation: 449613

Native PHP can not do this. The task is way out of PHP's scope.

Depending on the server OS and FTP server software used, however, PHP could call some shell scripts (or WMI / PowerShell scripts on Windows) that accomplish the task. This is not trivial to set up, though, especially not if it's to be done safely (without giving the PHP process root level privileges).

The question may be better suited on Serverfault.com.

Upvotes: 2

Related Questions