Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-12-2006, 05:27 PM   PM User | #1
SWG
New Coder

 
Join Date: Nov 2006
Location: Oklahoma City, Oklahoma, United States
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
SWG is an unknown quantity at this point
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.
SWG is offline   Reply With Quote
Old 11-12-2006, 05:41 PM   PM User | #2
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
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
ttttt is offline   Reply With Quote
Old 11-13-2006, 02:07 AM   PM User | #3
SWG
New Coder

 
Join Date: Nov 2006
Location: Oklahoma City, Oklahoma, United States
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
SWG is an unknown quantity at this point
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.
SWG is offline   Reply With Quote
Old 11-13-2006, 02:34 AM   PM User | #4
bcarl314
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
bcarl314 will become famous soon enough
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 ...

Quote:
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.
bcarl314 is offline   Reply With Quote
Old 11-13-2006, 03:13 AM   PM User | #5
SWG
New Coder

 
Join Date: Nov 2006
Location: Oklahoma City, Oklahoma, United States
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
SWG is an unknown quantity at this point
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.
SWG is offline   Reply With Quote
Old 11-13-2006, 05:03 AM   PM User | #6
SeeIT Solutions
Regular Coder

 
Join Date: May 2005
Posts: 563
Thanks: 0
Thanked 3 Times in 3 Posts
SeeIT Solutions is on a distinguished road
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
__________________
Design Portfolio
SeeIT Solutions is offline   Reply With Quote
Old 11-14-2006, 12:22 AM   PM User | #7
SWG
New Coder

 
Join Date: Nov 2006
Location: Oklahoma City, Oklahoma, United States
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
SWG is an unknown quantity at this point
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?
__________________
Signatures are for squares.

Last edited by SWG; 11-14-2006 at 12:53 AM..
SWG is offline   Reply With Quote
Old 11-15-2006, 12:12 PM   PM User | #8
SeeIT Solutions
Regular Coder

 
Join Date: May 2005
Posts: 563
Thanks: 0
Thanked 3 Times in 3 Posts
SeeIT Solutions is on a distinguished road
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.
__________________
Design Portfolio
SeeIT Solutions is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 02:23 AM.


Advertisement
Log in to turn off these ads.