FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 2nd, 2003, 09:14 AM
craigj craigj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Scotland, 55n53, 4w15
Posts: 124 craigj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 41 m 41 sec
Reputation Power: 6
PHP FTP functions

I am writing a script which should connect to an FTP server, state the current directory in a breadcrumb type manner, list the current directory and each list item should be a link (to either list the subdirectory or download a file). From examining the PHP FTP functions I have managed to write the following simple script:

<PHP>
<html>
<head>
<title>Server Name</title>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
</head>
<body>
<?

$ftp_server="127.0.0.1";
$ftp_user_name="user";
$ftp_user_pass="pass";

// set up basic connection
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
echo("Cannot connect to Server Name");
}

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

echo "<p>Server Name ", ftp_pwd($conn_id), "</p>";

// print each entry
echo "<p>";
foreach ($contents as $entry) {
echo $entry, "<br />";
}
echo "</p>";

// close connection
ftp_quit($conn);

?>
</body>
</html>
</PHP>

As you can see all this does is list the contents of the default directory and also state the current directory. I don't have a clue about how to make the list items into links.

One refinement I'd like to be able to make would be to only display certain file types eg. It would only list directorie s or .JPEG files. However if someone could even just help me with the first part I would be greatful. I read the Devshed PHP FTP articles but didn't really quite understand them (the uploading etc. just got in the way and confused me i think)

Reply With Quote
  #2  
Old June 2nd, 2003, 09:40 AM
drgroove's Avatar
drgroove drgroove is offline
pushing envelopes, not pencils
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Feb 2002
Posts: 6,225 drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level)drgroove User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Day 4 h 44 m 44 sec
Reputation Power: 174
If you're just listing out files in a directory, you might consider using PHP's file system functions instead of FTP...
http://us3.php.net/manual/en/ref.filesystem.php

Reply With Quote
  #3  
Old June 3rd, 2003, 06:54 AM
craigj craigj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Scotland, 55n53, 4w15
Posts: 124 craigj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 41 m 41 sec
Reputation Power: 6
I eventually plan to allow uploads to the FTP server and also have a login etc. which will track how much people are downloading uploading etc.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > PHP FTP functions


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT