Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script Post: Extremely Simple FTP Upload

    This is for ConfusedOfLife, it was a bit off subject from my post, so I started a new thread...

    Here's a basic ftp upload script:

    PHP Code:
    <?php

    $server 
    "127.0.0.1";
    $port 21;
    $to 120;

    $usr "john123";
    $pass "abc123";

    $src "source.php";
    $dest "destination.php";

    $ftp ftp_connect ($server$port$to);
    ftp_login ($ftp$usr$pass);
    ftp_put ($ftp$dest$srcFTP_BINARY);
    ftp_close($ftp);

    ?>
    You might also want to check out:
    http://www.php.net/manual/en/ref.ftp.php

    Nothing like going to the source.
    When I try to connect using the dns name of my server I get an error, but if I use the IP it works, just a little warning in case it happens to you too.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you! I didn't know about ftp_connect and I'm usually so dumb that I don't search!

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're going to use this alot, you might like it better as a class

    ftp.php
    PHP Code:
    <?php

    class FTP
    {
        function 
    FTP$server$port=21$to=120 )
        {
            
    $this->connection ftp_connect$server$port$to );
            if ( !
    $this->connection )
            {
                
    $this->throwError"Error connecting to FTP host" );
            }
            
    $this->mode       FTP_BINARY;
        }
        
        function 
    login$usr$pass )
        {
            if ( !
    ftp_login$this->connection$usr$pass ) )
            {
                
    $this->throwError"Username or Password invalid" );
            }
        }
        
        function 
    setMode$mode )
        {
            
    $this->mode $mode;
        }
        
        function 
    put$file$dest )
        {
            if ( !
    ftp_put$this->connection$dest$file$this->mode ) )
            {
                
    $this->throwError"File upload not successful" );
            }
        }
        
        function 
    kill()
        {
            
    ftp_close$this->connection );
        }
        
        function 
    throwError$msg )
        {
            die( 
    $msg );
        }
    }

    ?>
    And then, just include that sucker and interface it
    PHP Code:
    <?php

    include_once( "includes/ftp.php" );

    $ftp = new FTP"127.0.0.1" );
    $ftp->login"john123""abc123" );
    $ftp->put"source.php""destination.php" );
    $ftp->kill();

    ?>
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks beetle, you're cooooooooooooooool!

    One more question, when I fsockopen, the default port is 80, and about this one it's 21. How can we find the right port if it's not 21? The same questions is true for fsockopen, what if it wasn't 80?!

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hm, good question. I'll have to chew on that one a bit
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •