Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


 
 
LinkBack Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 04-15-2006, 12:20 AM   #1 (permalink)
Junior Member
 
cleo's Avatar
 
Join Date: 04-14-06
Location: Boston
Posts: 18
iTrader: 0 / 0%
Latest Blog:
None

cleo is liked by somebodycleo is liked by somebodycleo is liked by somebody
Send a message via MSN to cleo
FTP Login PHP Script from Website

Hi. I am looking to create a FTP login from my website.
It will have two fields, a username and pass.

My server/host connects from a broswer with 'ftp://specificuser@website.com' and locks the users into their directories.

The whole 'Username' would be 'specificuser@website.com'. That's fine.


1) The first problem is with the PHP script I found, I would have to to connect to a generic FTP address instead and this is not possible with the above scenario. I don't know how to modify the PHP code below.

2) Second problem. I'd like to take out the directory portion of the HTML. It's simple to remove but how does it relate to the PHP portion?


Can someone be kind enough to take a look at it?

Here is the HTML code referencing the ftp.php file:
HTML Code:
<form action="ftp.php/" method="POST"> <p>Username<input name="username"> <p>Password<input name="password" type="password"> <p><input name="login" type="submit" value="login"> </form>
Here is the PHP code:
PHP Code:
<?php

/*
*/

// quick "die" function
function funk_die($msg) {
    if(
$msg=='normal') {
return 
"<html><body><a href=\"ftp.php\">back</a></body></html>";
    }
}

// function to give dir listing stuff
function dir_funk () {

// cookie?
global $ftp;

// dir name
$dir=ftp_pwd($ftp);
// dir listing array
$dirlist=ftp_rawlist($ftp,$dir);

// print the directory listing
$funk "<html><body><p>current directory: <b> $dir </b></p>";
$funk .= "<p><a href=\"ftp.php?&updir=$dir\">go up one level</a>
</p>"
;


$funk .= "<p>
<table cellspacing=0 cellpadding=2 border=1>
<tr><td><b>permissions</b></td><td><b>file/directory</b></td>
<td><b>download</b></td><td><b>delete</b></td>
<td><b>chmod</b></td><td><b>rename</b></td>
</tr>
"
;

    while(list(
$i,$thingy)=each($dirlist)) {

$thingy=preg_replace("/\s+/"" "$thingy);

if(
$i==0) {
echo 
"";
} else {
list(
$chmod,$thing,$owner,$group,$size,$month,$day,$time,$filename)=explode(" ",$thingy);
    if(
ereg("d",$chmod)) {
$funk .= "<tr><td>$chmod</td><td><a href=\"ftp.php?dir=$dir/$filename\">$filename</a></td>
<td>dir</td>
<td><a href=\"ftp.php?delete=dir&thingy=$dir/$filename\">delete</a></td>
<td><a href=\"ftp.php?chmod=1&thingy=$dir/$filename\">chmod</a></td>
<td><a href=\"ftp.php?rename=$dir/$filename\">rename</a></td>
</tr>"
;
    } else {
$funk .= "<tr><td>$chmod</td><td>$filename</td>
<td><a href=\"ftp.php?dl=1&file=$dir/$filename\">d/l ($size)</a></td>
<td><a href=\"ftp.php?delete=file&thingy=$dir/$filename\">delete</a></td>
<td><a href=\"ftp.php?chmod=1&thingy=$dir/$filename\">chmod</a></td>
<td><a href=\"ftp.php?rename=$dir/$filename\">rename</a></td>
</tr>"
;
    }
}

    }

$funk .= "</table>
</p>"
;

$funk .= "<p>Create a new directory<br>
<form action=\"ftp.php\" method=\"POST\">
<input size=\"15\" name=\"name\">
<input type=\"hidden\" name=\"current_dir\" value=\"$dir\">
<input type=\"submit\" name=\"newdir\" value=\"create_dir\">
</form>
</p>"
;

$funk .= "<p>Upload a local file<br>
<form action=\"ftp.php\" method=\"POST\">
<input type=\"file\" name=\"localfile\"><br>
<input type=\"hidden\" name=\"current_dir\" value=\"$dir\">
<input type=\"submit\" name=\"upload\" value=\"upload_file\">
</form>
</p>"
;

$funk .= "</body></html>";

return 
$funk;
}


if(!
$login) {
// print the login form

echo "<html><body><p><b>ftp login</b><hr></p>
<form action=\"ftp.php\" method=\"POST\">
<p>Your server (eg ftp.yoursite.com)<br> <input size=\"30\" name=\"server\"></p>
<p>Username <br> <input size=\"30\" name=\"username\"></p>
<p>Password <br> <input size=\"30\" name=\"password\"></p>
<p><input type=\"submit\" name=\"login\" value=\"login\"></p>
</form></body></html>"
;
} else {

// try to connect or die with an error
$ftp=ftp_connect($server) or die("invalid server");
// try to login or die with error
$conn=ftp_login($ftp,$username,$password) or die("login failed for some reason");
// set a cookie so the !$login form above is never displayed
setcookie("login","active");
// set goody cookies
setcookie("server",$server);
setcookie("username",$username);
setcookie("password",$password);

    if(
$dir) {

ftp_chdir($ftp,$dir);
echo 
dir_funk();

    } elseif(
$dl) {

        if(
$get) {

if(!
$local) {
die(
"please enter a value");
}

ftp_get($ftp$local$fileFTP_BINARY);
echo 
funk_die(normal);

        } else {
echo 
"<html><body>";
echo 
"download file";
$size=ftp_size($ftp,$file);
$time=ftp_mdtm($ftp,$file);
$time=date("d M Y, H i",$time);
echo 
"<p><table cellspacing=0 cellpadding=2 border=1>
<tr><td><b>filename</b></td><td><b>size</b></td>
<td><b>date modified</b></td></tr>
<tr><td>$file</td><td>$size</td><td>$time</td></tr></table>"
;
echo 
"<form action=\"ftp.php\" method=\"POST\">
where to download the file to (/home/me/file.txt or c:/file.txt):<br>
<INPUT NAME=\"local\" size=\"40\">
<input type=\"hidden\" name=\"dl\" value=\"1\">
<input type=\"hidden\" name=\"file\" value=\"$file\"><br>
<INPUT TYPE=\"submit\" name=\"get\" VALUE=\"download file\">
</FORM>"
;
echo 
"</body></html>";

        }

    } elseif(
$rename) {

        if(
$do) {

if(!
$val) {
die(
"please enter a value");
}

ftp_rename($ftp$rename$val);
echo 
funk_die(normal);

        } else {

echo 
"<html><body>
rename this file: $rename
<p>
<form action=\"ftp.php\" method=\"POST\">
Rename to: <input size=\"50\" name=\"val\" value=\"$rename\"><br>
<input type=\"hidden\" name=\"rename\" value=\"$rename\">
<input type=\"submit\" name=\"do\" value=\"rename\">
</form>
</body></html>"
;

        }

    } elseif(
$chmod) {

        if(
$do) {

if(!
$val) {
die(
"please enter a value");
}

$cmd="CHMOD $val $file";
ftp_site($ftp$cmd);
echo 
funk_die(normal);

        } else {

echo 
"<html><body>
chmod this file: $thingy
<p>
<form action=\"ftp.php\" method=\"POST\">
<input size=\"4\" name=\"val\" maxlength=\"4\"> CHMOD value<br>
<input type=\"hidden\" name=\"file\" value=\"$thingy\">
<input type=\"hidden\" name=\"chmod\" value=\"1\">
<input type=\"submit\" name=\"do\" value=\"chmod\">
</form>
</body></html>"
;

        }

    } elseif(
$delete) {

        if(
$delete=='file') {
ftp_delete($ftp$thingy);
        } elseif(
$delete=='dir') {
ftp_rmdir($ftp$thingy);
        }
echo 
funk_die(normal);

    } elseif(
$upload) {

if(!
$localfile) { die("please enter a file"); }

$file substrstrrchr$localfile"/" ), );
$put_thingy $current_dir "/" $file;
ftp_put($ftp$put_thingy$localfileFTP_BINARY);
echo 
funk_die(normal);

    } elseif(
$newdir) {
    
if(!
$name) { die("please enter a name"); }

$newdir $current_dir "/" $name;
ftp_mkdir($ftp,$newdir);
echo 
funk_die(normal);

    } elseif(
$updir) {

$newdir str_replacesubstrstrrchr$updir"/" ), ) , ""$updir);

ftp_chdir($ftp,$newdir);
echo 
dir_funk();

    } else {

echo 
dir_funk();

    }
}

?>
Could someone show me proper working code please?
cleo is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forum Login For Website forevercharmed Coding Forum 3 04-23-2006 05:16 PM
Site login and phpBB login SVB Coding Forum 13 08-02-2004 07:32 PM
Problems with Login Script Izzmo Coding Forum 15 02-10-2004 03:57 PM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 03:52 AM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.