创建filezilla ftp帐户需要PHP脚本

时间:2012-04-16 03:35:58

标签: php ftp filezilla

好的,所以我有filezilla服务器软件设置,但我想要一个php脚本,它会将新用户添加到包含用户名,密码和文件夹的xml文件中。我希望它将它添加到现有的xml文件而不删除其中的当前信息。如果您知道可用的方法或脚本来执行此操作,请将其发送给我或分享您的知识。否则,如果有另一个ftp服务器程序具有单独的xml或每个用户的文件,请告诉我。 提前致谢, 太

2 个答案:

答案 0 :(得分:2)

您最好的选择是使用SimpleXML来操纵XML文件。

  1. 使用simplexml_load_file打开文件。确保您具有该文件的读/写权限。
  2. 使用SimpleXMLElement类添加和删除节点。

答案 1 :(得分:1)

 $user = $xml->Users->addChild('User');
 $user->addAttribute('Name', $user_name);

 add_option($user,'Pass',md5($password));
 add_option($user,'Group',null);
 add_option($user,'Bypass server userlimit','0');
 add_option($user,'User Limit','0');
 add_option($user,'IP Limit','0');
 add_option($user,'Enabled','1');
 add_option($user,'Comments','none');
 add_option($user,'ForceSsl','0');

 $filter = $user->addChild('IpFilter');
 $filter->addChild('Disallowed');
 $filter->addChild('Allowed');

 $permissions = $user->addChild('Permissions');
 $permission = $permissions->addChild('Permission');

 $permission->addAttribute('Dir', str_replace("/","\\",$ftpUserFolder));

 add_option($permission,'FileRead','1');
 add_option($permission,'FileWrite','1');
 add_option($permission,'FileDelete','1');
 add_option($permission,'FileAppend','1');
 add_option($permission,'DirCreate','1');
 add_option($permission,'DirDelete','1');
 add_option($permission,'DirList','1');
 add_option($permission,'DirSubdirs','1');
 add_option($permission,'IsHome','1');
 add_option($permission,'AutoCreate','1');

 $speed = $user->addChild('SpeedLimits');
 $speed->addAttribute('DlType', '1');
 $speed->addAttribute('DlLimit', '10');
 $speed->addAttribute('ServerDlLimitBypass', '0');
 $speed->addAttribute('UlType', '1');
 $speed->addAttribute('UlLimit', '10');
 $speed->addAttribute('ServerUlLimitBypass', '0');
 $speed->addChild('Download');
 $speed->addChild('Upload');

 if(!$rv = $xml->asXML($xmlfile)){
  echo ('SimpleXML could not write file');
  return false;
 }


 //Change file encoding from UTF8 to ISO-8859-1
 $dom = new DOMDocument("1.0","ISO-8859-1");
 $dom->preserveWhiteSpace = false;
 $dom->formatOutput = true;
 if(!$dom->load($xmlfile) || !$dom->save($xmlfile)){
  echo ('DOMDocument could not change file enconding from UTF8 to ISO-8859-1');

我的博客中的完整脚本: http://moshez.blogspot.co.il/2013/02/php-filezilla-ftp-server-auto-create.html