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 8 of 8
  1. #1
    SWG
    SWG is offline
    New Coder
    Join Date
    Nov 2006
    Location
    Oklahoma City, Oklahoma, United States
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Connecting to FTP

    Hello. I'm trying to connect with FTP to run a CHMOD command or whatever you want to call it with PHP.

    PLEASE READ THIS:
    http://codingforums.com/showthread.p...d=1#post504574

    There it will explain exactly what I'm trying to do... But for now, I'll give you the 411. I've erased all coding and I'm starting from scratch just for testing. So, basically, all that coding you saw on the previous page is worthless for now.

    PHP.net MANUAL - CHMOD:
    http://us3.php.net/manual/en/function.chmod.php

    If you scroll down on that page, you'll see how they connected with FTP. I don't understand much of any of it...

    So, basically, what does every each and every part of that coding mean? How does it work when it's all put together?

    Thanks in advance.
    Signatures are for squares.

  • #2
    Regular Coder ttttt's Avatar
    Join Date
    Oct 2005
    Posts
    372
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If this is what you don't understand:
    PHP Code:
    <?php
    // Read and write for owner, nothing for everybody else
    chmod("/somedir/somefile"0600);

    // Read and write for owner, read for everybody else
    chmod("/somedir/somefile"0644);

    // Everything for owner, read and execute for others
    chmod("/somedir/somefile"0755);

    // Everything for owner, read and execute for owner's group
    chmod("/somedir/somefile"0750);
    ?>
    then basically you have to connect to the ftp server. Then the first part of the code:
    PHP Code:
    chmod(
    Sets the php chmod fuction.
    Then:
    PHP Code:
    /somedir/somefile", 
    specifies the server path. You can look into this in more detail by using your ftp client, which may well display the server path as you browse.
    Finally:
    PHP Code:
     0755); 
    Is the unix number you want to chmod to.
    ttttt
    http://openoffice.org/- Microsoft Office without the Microsoft.
    [home page][forum]
    Versatile, free software

  • #3
    SWG
    SWG is offline
    New Coder
    Join Date
    Nov 2006
    Location
    Oklahoma City, Oklahoma, United States
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you read the last post of the thread I posted... the CHMOD function doesn't work on all servers sometimes or something. So, basically, I can't do that. I meant the FTP connection example they have at the bottom of the page was what I didn't understand. I understood the CHMOD command.
    Signatures are for squares.

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    I don't think adding in an FTP connection is the way to go. You're going to be passing your username / password in clear text over the internet on every page request. I'd shy away from that approach if possible.

    I think the relevant information from php.net is this ...

    Note: The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.

    Note: This function will not work on remote files as the file to be examined must be accessible via the servers filesystem.

    Note: When safe mode is enabled, PHP checks whether the files or directories you are about to operate on have the same UID (owner) as the script that is being executed. In addition, you cannot set the SUID, SGID and sticky bits.
    My guess is your server has php safe_mode enabled and the file you are trying to chmod does not have the same owner as required to chmod the file.

  • #5
    SWG
    SWG is offline
    New Coder
    Join Date
    Nov 2006
    Location
    Oklahoma City, Oklahoma, United States
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It wouldn't be sending a user name and password. :S. Didn't you people read the thread? :P

    It will create a file and write a MySQL connection in it with the provided content in the form fields. So, it doesn't matter.
    Signatures are for squares.

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    There is another way to CHMOD and it works on different servers. I've had the problem where chmod() didnt work but this did.


    Try this
    PHP Code:
    //path to filename is relative to the current FTP directory so if you want to modify a file in the root called 'filename.txt' use this:
    $conn_id ftp_connect('SERVER');
    $login_result ftp_login($conn_id,'USERNAME','PASSWORD');
    ftp_site($conn_id,"CHMOD 777 filename.txt");

    //if the file is in a directory called directory you can use 
    $conn_id ftp_connect('SERVER');
    $login_result ftp_login($conn_id,'USERNAME','PASSWORD');
    ftp_site($conn_id,"CHMOD 777 directory/filename.txt");

    // OR
    $conn_id ftp_connect('SERVER');
    $login_result ftp_login($conn_id,'USERNAME','PASSWORD');
    ftp_chdir($conn_id'directory');
    ftp_site($conn_id,"CHMOD 777 filename.txt"); 
    Hope that helps

  • #7
    SWG
    SWG is offline
    New Coder
    Join Date
    Nov 2006
    Location
    Oklahoma City, Oklahoma, United States
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?
    if(!isset($_POST['submit'])) {
    echo 
    "Form requiring user name and password.";
    } else {
    The code you showed me except with a $user_name $_POST['variable']; etc.
    }
    ?>
    It'd still work if I did this, right? They'd also have to type in the path... So could it be "CHMOD 777 $path"? Wouldn't it CHMOD the directory?
    Last edited by SWG; 11-14-2006 at 01:53 AM.
    Signatures are for squares.

  • #8
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well you have to change the username and password etc because I'm sure your users don't have them set as USERNAME and PASSWORD They can come from wherever you want, post variables, defines, hard coded whatever.

    You can use the post submit thing, the only thing I showed was how to CHMOD a file. The username and password need to be the ftp username and password and the server has to be correct. Also, you will need to get the path right, and I don't know if alot of users (without much knowledge) would know how to fill that in.


  •  

    Posting Permissions

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