开发者

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

开发者 https://www.devze.com 2023-01-23 17:22 出处:网络
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.

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!


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.


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号