FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Creating a FTP directory using PHP

 


matt87
Okay, I looked everywhere and could not find how to do this. I have my own FTP server I am hosting using my computer and I want a script that would connect to the FTP server and list all the files from the server. I know that people can connect directly to the ftp server to see the files but it doesn't work out that good. I want it to be implemented in my site so when they click on a file it downloads it rather then opening it. I don't know if you can get what I am trying to say or not. I am ost myself. If you can please help me or have any idea on how to start something like this please post.
holadola
Use the PHP ftp-functions
http://www.php.net/manual/en/ref.ftp.php
ml
example

Code:
<?php
// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
       echo "FTP connection has failed!";
       echo "Attempted to connect to $ftp_server for user $ftp_user_name";
       exit;
   } else {
       echo "Connected to $ftp_server, for user $ftp_user_name";
   }

// get contents of the current directory
$contents = ftp_nlist($conn_id, ".");

// check upload status
if (!$upload) {
       echo "FTP upload has failed!";
   } else {
       echo "Uploaded $source_file to $ftp_server as $destination_file";
   }

// close the FTP stream
ftp_close($conn_id);

// output links
$ftp_servers_url_for_http = "http://yourserver.tld/";
foreach($contents as $c) {
      echo "<a href=\"".$ftp_servers_url_for_http.$c."\">".$c."</a><br>\r\n";
}

?>
matt87
That code is not quite what I am looking for. I want a little more and my php skills are lacking greatly. I learned some a long time ago and forgot it since then. I need to make it list the directories and then the sub-directories and then the files then show how many times a files been downloaded and so on. Its a lot to do manually thats why I am looking for such a script.
thnn
php.net should help you to find out stuff.

Remember its your friend.

I can post a message on the PHP usergroup I belong to otherwise and ask how.
matt87
thnn wrote:
php.net should help you to find out stuff.

Remember its your friend.

I can post a message on the PHP usergroup I belong to otherwise and ask how.


Thanks, I would really appreciate that.
Grimboy
If you don't know much php your best chance would be to edit the source code for one of the following:

http://inebria.com/phpftp/
http://www.raditha.com/php/ftp/
http://www.net2ftp.com/
matt87
Grimboy wrote:
If you don't know much php your best chance would be to edit the source code for one of the following:

http://inebria.com/phpftp/
http://www.raditha.com/php/ftp/
http://www.net2ftp.com/


That not actually what I am looking for. That is FTP transfering using php. What I am looking for is a little diffrent. It is getting a FTP directory from my server and listing all the files using php and keep track of how many downloads of each file. I know there is something out there that can do this I just can't find it.
Grimboy
That's just a matter of ripping out a few parts of the program. Are you too high and mighty to get your hands dirty. Anyway you should be logging people on useing an annonymas(sp?) account so that they don't have the permission to do anything but view and download stuff.
matt87
Grimboy wrote:
That's just a matter of ripping out a few parts of the program. Are you too high and mighty to get your hands dirty. Anyway you should be logging people on useing an annonymas(sp?) account so that they don't have the permission to do anything but view and download stuff.


I use a program called BulletProof FTP Server. It allows me to add user accounts and limit them to what they can do and how much they can download/upload.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.