Jump to content

FTP client.


adam291086

Recommended Posts

I have this function for my FTP client and i am tring to remove the . and .. dir but nothing is happening you can see whats happening here  http://www.rubberduckiee.co.uk/admin/FTP/ftp.php

 

function ShowFiles()
{
$conn = DoConn();
$currDir = "";

// Get the name of the current directory
if(isset($_GET["currDir"]))
$currDir = $_GET["currDir"];
else
$currDir = ftp_pwd($conn);


// Retrieve a list of files and directories
// and display the appropriate icon for each
$fList = @ftp_nlist($conn, $currDir);

// We will work out the parent directory
$parentDir = strrev($currDir);
$parentDir = ereg_replace("^[a-zA-Z0-9\-]*/", "", $parentDir);
$parentDir = strrev($parentDir);
?>
<img src='parent.gif'>
<a href='ftp.php?command=listFiles&currDir=<?php echo $parentDir; ?>'>
Back
</a>
<br>

<?php

for($i = 0; $i < sizeof($fList); $i++)
{
// We will remove the parent directory (if any)
// from the name of the file that gets displayed
$trimFile = ereg_replace("^$currDir", "", $fList[$i]);

// Remove any forward slash at front of name
$trimFile = ereg_replace("^/", "", $trimFile);

if($fList[$i] == '.')
$i++;

if(@ftp_chdir($conn, $fList[$i]))
{
@ftp_cdup($conn);
?>
<img src='folder.gif'>
<a href='ftp.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'>
<?php echo $trimFile; ?>
</a>
<br>
<?php
}
else
{
?>
<img src='file.gif'>
<a href='ftp.php?command=getFile&currFile=<?php echo $fList[$i]; ?>&currDir=<?php echo $currDir; ?>'>
<?php echo $trimFile; ?>
</a>
<br>
<?php
}
}
}

Link to comment
Share on other sites

incorporate this in the appropriate spot....

<?php

if($fList[$i] == '.' || $fList[$i] == '..') // from what I can tell, $fList[$i] is the actual dir listing.
{
    // skip these and move on to the next item
}
else
{
     // show the links as the current dir is not . or ..
}

?>

Link to comment
Share on other sites

i have added in that and the . and .. are still appearing.

 

here is the function

 

function ShowFiles()
{
$conn = DoConn();
$currDir = "";

// Get the name of the current directory
if(isset($_GET["currDir"]))
$currDir = $_GET["currDir"];
else
$currDir = ftp_pwd($conn);


// Retrieve a list of files and directories
// and display the appropriate icon for each
$fList = @ftp_nlist($conn, $currDir);

for($i = 0; $i < sizeof($fList); $i++)
{
// We will remove the parent directory (if any)
// from the name of the file that gets displayed
$trimFile = ereg_replace("^$currDir", "", $fList[$i]);

// Remove any forward slash at front of name
$trimFile = ereg_replace("^/", "", $trimFile);

if($fList[$i] == '.' || $fList[$i] == '..') 
{
$i++;
}
else
{


if(@ftp_chdir($conn, $fList[$i]))
{
@ftp_cdup($conn);
?>
<img src='folder.gif'>
<a href='ftp.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'>
<?php echo $trimFile; ?>
</a>
<br>
<?php
}
else
{
?>
<img src='file.gif'>
<a href='ftp.php?command=getFile&currFile=<?php echo $fList[$i]; ?>&currDir=<?php echo $currDir; ?>'>
<?php echo $trimFile; ?>
</a>
<br>
<?php
}
}
}
}

Link to comment
Share on other sites

i have found away around it by setting the for loop to start with 2 therefore missing the first two bits of information out of the array. Is this the best way to go about it?

 

for($i = 2; $i < sizeof($fList); $i++)

 

$fList is the array that contains all the files and folders.

 

it just seems the If statement wasn't working at all

Link to comment
Share on other sites

I usually do the reverse of what you have:

<?php
if($fList[$i] != '.' || $fList[$i] != '..') 
{ 
if(@ftp_chdir($conn, $fList[$i]))
{ 
	@ftp_cdup($conn); ?>
	<img src='folder.gif'> <a href='ftp.php?command=listFiles&currDir=<?php echo $fList[$i]; ?>'> <?php echo $trimFile; ?> </a> <br>
<?php
} else {
?>
	<img src='file.gif'> <a href='ftp.php?command=getFile&currFile=<?php echo $fList[$i]; ?>&currDir=<?php echo $currDir; ?>'> <?php echo $trimFile; ?> </a> <br>
<?php
}
}

 

Using the != should skip past them with no problem

Link to comment
Share on other sites

next problem i am having with the downloading of a file. Heres the function

 

function GetFile() 

{ 

$filename = $_GET['currFile'];
$filename = str_replace("/rubberduckiee","",$filename);

$filename='www.rubberduckiee.co.uk'.$filename;

// required for IE, otherwise Content-disposition is ignored

if(ini_get('zlib.output_compression'))

  ini_set('zlib.output_compression', 'Off');



// addition by Jorg Weske

$file_extension = strtolower(substr(strrchr($filename,"."),1));



if( $filename == "" ) 

{

  echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";

  exit;

} elseif ( ! file_exists( $filename ) ) 

{
echo $filename;

  echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found.</body></html>";

  exit;

};

switch( $file_extension )

{

  case "pdf": $ctype="application/pdf"; break;

  case "exe": $ctype="application/octet-stream"; break;

  case "zip": $ctype="application/zip"; break;

  case "doc": $ctype="application/msword"; break;

  case "xls": $ctype="application/vnd.ms-excel"; break;

  case "ppt": $ctype="application/vnd.ms-powerpoint"; break;

  case "gif": $ctype="image/gif"; break;

  case "png": $ctype="image/png"; break;

  case "jpeg":

  case "jpg": $ctype="image/jpg"; break;

  default: $ctype="application/force-download";

}

header("Pragma: public"); // required

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: private",false); // required for certain browsers 

header("Content-Type: $ctype");

// change, added quotes to allow spaces in filenames, by Rajkumar Singh

header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );

header("Content-Transfer-Encoding: binary");

header("Content-Length: ".filesize($filename));

readfile("$filename");

exit();

}

 

someone sent me this code a while ago. I get the error message saying file not found. But if i echo out $file and copy it into the url the file loads? Whats happening. Any help is appreciated

Link to comment
Share on other sites

right i now have it finding the file but instead of downloading the file all i get it

 

{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf330 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0 \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural \f0\fs24 \cf0 dgdfgdfgdfgg}

 

outputted to the screen . What am i doing wrong

Link to comment
Share on other sites

OK i have got everything working.

 

Secuirty wise i know this isn't a good idea. But i have implemented a check.

 

i check the current directory the user is looking at. If its not where they are supposed to be then they get an error message.

 

I check the curr directory name against a session which is set on loging in. Is this enough to keep it secure?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.