unknowncheats uc-forum.com ucdownloads ucdownloads.com

Go Back   UC-Tutorials - Multiplayer Game Hacking and Cheat Tutorials > Web / Scripting > PHP

- Sponsored Advertisement -
http://www.myfpscheats.com/


Reply
 
Thread Tools Display Modes
  #1  
Old 12-23-2006, 07:47 AM
zero_tolerance zero_tolerance is offline
Senior Member
 
Join Date: Dec 2006
Posts: 289
Default Austin's PHP Tutorial - Connecting To FTP and displaying directory

By AustinMini

Alright, this php is abit more advanced then the rest posted here. I just thought id show you guys some more complicated stuff involving a class.

Alright, so first of all we need to create a class.
PHP Code:
class ftp
{

Now we need to create some vars and functions in this class.

PHP Code:
class ftp
{
    var 
$_server NULL;
    var 
$_login NULL;
    
    function 
ftp $username$password$server )
    {
        
$this->_server = @ftp_connect $server );
        
$this->_login = @ftp_login $this->_server$username$password );

        if ( ! 
$this->_server )
        {
            die ( 
"Sorry, unable to connect to the server ( $server )" );
        }

        if ( ! 
$this->_login )
        {
            die ( 
"Sorry, the login, ( $username ), or password, ( $password ), was incorrect." );
        }
        else
        {
            echo 
" Succesfully connected to ( $server ) on user ( $username ) <br />";
        }
    }
    
    function 
flist()
    {
    
$files ftp_nlist($this->_server".");
    foreach (
$files as $file)
        {
          echo 
"<br>$file";
        }
    }
    function 
close()
    {
        @
ftp_close($this->_server);
    }
    

Alright, by looking at that big amount of functions and vars, you are probably pretty confused. Let me break it down abit for you.

The first function i made is used to connect to the FTP server.
This code is simply trying the username and password and telling you if it worked or not.
PHP Code:
function ftp $username$password$server )
    {
        
$this->_server = @ftp_connect $server );
        
$this->_login = @ftp_login $this->_server$username$password );

        if ( ! 
$this->_server )
        {
            die ( 
"Sorry, unable to connect to the server ( $server )" );
        }

        if ( ! 
$this->_login )
        {
            die ( 
"Sorry, the login, ( $username ), or password, ( $password ), was incorrect." );
        }
        else
        {
            echo 
" Succesfully connected to ( $server ) on user ( $username ) <br />";
        }
    } 
The second function needed is the function to display the files in the server.

PHP Code:
    function flist()
    {
    
$files ftp_nlist($this->_server".");
    foreach (
$files as $file)
        {
          echo 
"<br>$file";
        }
    } 
And the third function is the function used to close the connection.

PHP Code:
    function close()
    {
        @
ftp_close($this->_server);
    } 
And Last, but not least, we need to create the forms.
In this code, we create a form with the textboxes and everything we need, we also have another PHP script at the bottom, this is used if the server the person wants to connect to uses an anonymous account. If the person doesnt enter a username, it is automaticaly set to anonymous.

PHP Code:
<html>
<title>FTP Connect</title>
<body>
<form method="POST" action="<?php echo basename(__FILE__); ?>">
  <P CLASS="centeralign"> Ftp Server:<br />
    <input type="text" size="20" maxlength="30" name="server">
    <br />
    Username:<br />
    <input type="text" size="20" maxlenghth="20" name="username">
    <br />
    Password:<br />
    <input type="password" size="20" maxlenghth="20" name="password">
    <br />
    <br />
    <input type="submit" value="Connect!">
<br />
<br />
  </P>
</form>
<div align="center">
</div>
</body>
</html>

<?php
$serv 
$_POST["server"];
$user $_POST["username"];
$pass $HTTP_POST_VARS["password"];

if ( empty(
$user) )
    {
    
$user 'anonymous'
    
}

if ( !empty(
$serv) && !empty($user) )
    {
    
$ftp = new ftp "$user""$pass""$serv);
    
$ftp->flist();
    
$ftp->close();
    }
?>
And here is the complete sourcecode.
Sorry if i didnt explain well enogh this is my first tutorial. Let me know comments or if you want me to change anything

PHP Code:
<?php
class ftp
{
    var 
$_server NULL;
    var 
$_login NULL;
    
    function 
ftp $username$password$server )
    {
        
$this->_server = @ftp_connect $server );
        
$this->_login = @ftp_login $this->_server$username$password );

        if ( ! 
$this->_server )
        {
            die ( 
"Sorry, unable to connect to the server ( $server )" );
        }

        if ( ! 
$this->_login )
        {
            die ( 
"Sorry, the login, ( $username ), or password, ( $password ), was incorrect." );
        }
        else
        {
            echo 
" Succesfully connected to ( $server ) on user ( $username ) <br />";
        }
    }
    
    function 
flist()
    {
    
$files ftp_nlist($this->_server".");
    foreach (
$files as $file)
        {
          echo 
"<br>$file";
        }
    }
    function 
close()
    {
        @
ftp_close($this->_server);
    }
    


?>
<html>
<title>FTP Connect</title>
<body>
<form method="POST" action="<?php echo basename(__FILE__); ?>">
  <P CLASS="centeralign"> Ftp Server:<br />
    <input type="text" size="20" maxlength="30" name="server">
    <br />
    Username:<br />
    <input type="text" size="20" maxlenghth="20" name="username">
    <br />
    Password:<br />
    <input type="password" size="20" maxlenghth="20" name="password">
    <br />
    <br />
    <input type="submit" value="Connect!">
<br />
<br />
  </P>
</form>
<div align="center">
</div>
</body>
</html>

<?php
$serv 
$_POST["server"];
$user $_POST["username"];
$pass $HTTP_POST_VARS["password"];

if ( empty(
$user) )
    {
    
$user 'anonymous'
    
}

if ( !empty(
$serv) && !empty($user) )
    {
    
$ftp = new ftp "$user""$pass""$serv);
    
$ftp->flist();
    
$ftp->close();
    }
?>
+rep please if you found this useful.
Reply With Quote
Reply

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit

Tags
austin, connecting, directory, displaying, ftp, php, tutorial

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 08:31 PM.