ftp_site() , I am using this command to tell the server

Alles, was PHP betrifft, kann hier besprochen werden.

ftp_site() , I am using this command to tell the server

Postby aj123cd » 19. September 2009 08:28

ftp_site() , I am using this command to tell the server about new user .
(create a ftp user account using php /window’s platform)
This is my code.
<? php

//ftp_site — Sends a SITE command to the server

$group = "ftp_private";// FileZilla server GROUP
$username ="newuser"; // NEW USER
$password = "password"; // NEW USER password

ftp_site($ftp_stream,"SITE ADDUSER $group $username $password");

if (ftp_site($ftp_stream,'SITE ADDUSER $group $username $password'))
{ echo "Command executed successfully.\n"; }
else
{ die('Command failed.');
}
?>

I am getting error

Warning: ftp_site() expects parameter 1 to be resource, null given in C:\xampp\htdocs\shall\site.php on line 9

Warning: ftp_site() expects parameter 1 to be resource, null given in C:\xampp\htdocs\shall\site.php on line 11
Command failed.

Can anyone tell me where i am going wrong?
Thank U all
aj123cd
 
Posts: 62
Joined: 03. June 2009 08:19
Location: London,UK

Re: ftp_site() , I am using this command to tell the server

Postby Nobbie » 19. September 2009 10:12

1) You neither did a ftp_connect() nor a ftp_login(). You must do *both* before sending any commands to a remote server.

2) I dont think you will succeed in sending "SITE ADDUSER ....". The SITE-Command ist a non-standard FTP-Command, and depends on the FTP Server you are dealing with. But i have never heard about any server, which supports an "ADDUSER" command.

For example, the proftpd-Server supports the following three SITE commands (from http://www.proftpd.de/FTP-Befehle.38.0.html)

CHGRP
Short for CHange GRouP. Example: SITE CHGRP ftpgroup script.cgi

CHMOD
Short for CHange MODe. Example: SITE CHMOD 755 script.cgi

HELP


In order to find out, which SITE commands are supported by your FTP Server, you should go for the documentation. But I am pretty sure, that there will be no "ADDUSER" command (that would end up in a horrible securitiy hole).

P.S.: I just found that in your code

>FileZilla server GROUP

That means, you are running on a FileZilla FTP Server. In that case you may finish all actions, FileZilla does not support *any* SITE command.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: ftp_site() , I am using this command to tell the server

Postby aj123cd » 19. September 2009 10:36

Thank u Nobbie
So how can I tell the fileZila FTP server the user name and password for new users?
In other word, how can I update the ftp server with customer login details?
What is the ftp server can be automatically update the user details once they are registered.
Thank u
aj123cd
 
Posts: 62
Joined: 03. June 2009 08:19
Location: London,UK

Re: ftp_site() , I am using this command to tell the server

Postby Nobbie » 19. September 2009 12:45

aj123cd wrote:So how can I tell the fileZila FTP server the user name and password for new users?


You must run the FileZilla Server Admin Tool, which maybe local on the server. There you can enter new users and groups.

You *can* do that remote from another PC, but still you *must* use the Filezilla Admin Tool. You *cannot* do that via browser (HTTP) or via PHP Script. You *must* do that manually.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: ftp_site() , I am using this command to tell the server

Postby aj123cd » 19. September 2009 17:51

Other than PHP, can I automate the login in process?
aj123cd
 
Posts: 62
Joined: 03. June 2009 08:19
Location: London,UK

Re: ftp_site() , I am using this command to tell the server

Postby Nobbie » 19. September 2009 19:42

aj123cd wrote:Other than PHP, can I automate the login in process?


The "login process" can be done with each language (PHP, Perl, C) that supports FTP Protocoll.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: ftp_site() , I am using this command to tell the server

Postby aj123cd » 20. September 2009 07:13

Nobbie wrote:
aj123cd wrote:Other than PHP, can I automate the login in process?


The "login process" can be done with each language (PHP, Perl, C) that supports FTP Protocoll.


Thank u Nobbie.
Can you please give me some example? It would be g8 help to me.
I have spent all last week in this PHP/FTP login.
(In HTTP I can do register/login in php but not ftp)
Thanks.
aj123cd
 
Posts: 62
Joined: 03. June 2009 08:19
Location: London,UK

Re: ftp_site() , I am using this command to tell the server

Postby Nobbie » 20. September 2009 09:35

aj123cd wrote:Can you please give me some example? It would be g8 help to me.


From http://www.php.net/manual/en/function.ftp-login.php:

Code: Select all
Example #1 ftp_login() example
<?php
                     
$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server\n";
} else {
    echo "Couldn't connect as $ftp_user\n";
}

// close the connection
ftp_close($conn_id); 
?>


You should bookmark the www.php.net documentation, there are plenty of code snippets which can help you in understanding PHP.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: ftp_site() , I am using this command to tell the server

Postby aj123cd » 21. September 2009 10:02

Thank U Nobbie
I can work most of the PHP-FTP.
I have a website where user can register, create username and password, it will be store all the details in log file (MySQL).
I want o do same in FTP. When the users register i want to store the user name and password in ftp server. So customer can access ftp server.
Can it possible?
aj123cd
 
Posts: 62
Joined: 03. June 2009 08:19
Location: London,UK

Re: ftp_site() , I am using this command to tell the server

Postby Nobbie » 21. September 2009 13:08

aj123cd wrote:When the users register i want to store the user name and password in ftp server. So customer can access ftp server.
Can it possible?


It depends.

Each ftp sever (in conjunction to the operating system, where the server is running) has its own way of managing users and password.

You must find out, whether there is any FTP Server Software, which can be modified at runtime by a PHP Script, in order to insert new users into the (specific) user database.

Some Unix-based servers use the standard /etc/password and /etc/group files for user management, so you need root-access for modifying these files. If you have good knowledge about linux, you may try to write a shell script, which substitutes userid on execution ("Sticky bit") and which enters new users by invoking the "adduser" command.

Perhaps you will find other FTP Servers (like ProFTP), which also supports their own files for user management. It is always a question of sufficiant rights, when you want to modify such files at runtime via PHP Scripts. There is no unique "yes" or "no" to your question, you have to work it out on yourself.
Nobbie
 
Posts: 13171
Joined: 09. March 2008 13:04

Re: ftp_site() , I am using this command to tell the server

Postby aj123cd » 21. September 2009 19:22

Thank U Nobbie
G8 Full to me.
aj123cd
 
Posts: 62
Joined: 03. June 2009 08:19
Location: London,UK


Return to PHP

Who is online

Users browsing this forum: No registered users and 20 guests