?
Solved

Find the physical path of file

Posted on 2004-08-04
10
Medium Priority
?
590 Views
Last Modified: 2008-03-06
Hi

I've played around with code like this:

<?php
$conn_id = ftp_connect("xxx.com");
$login_result = ftp_login($conn_id, "user", "passw");
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
die;
} else {
echo "Connected";
}
$contents = ftp_nlist($conn_id, ".");
echo implode($contents,"/");
ftp_quit($conn_id);
?>

This code shows the files in a ftp-directory but I would also like to show the physical path to the individual files. Is this possible? Points to those who integrate the necessary code in the above.

Thanx,

Soren
0
Comment
Question by:speder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 210 total points
ID: 11723551
I don't understand exactly what you want but I guess it is something like this (sorry, I can't test the script right now)

<?php
$conn_id = ftp_connect("xxx.com");
$login_result = ftp_login($conn_id, "user", "passw");
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
die;
} else {
echo "Connected";
}
$currentdir = ftp_pwd();
$contents = ftp_nlist($conn_id, ".");
$all = implode($contents,":");
$all = str_replace(":",":$currentdir",$all);
echo ($all);
ftp_quit($conn_id);
?>

0
 

Author Comment

by:speder
ID: 11723644
I think this only returns the directory name. I would like it to return the physical path to the individual files. Like the asp-function Server.MapPath.
0
 
LVL 3

Assisted Solution

by:thecode101
thecode101 earned 90 total points
ID: 11727078
If the ftp user is set up to log in to the root directory on the server then the ftp_pwd() will return the entire phsyical directory of the file and Jaime's code should work.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:speder
ID: 11727396
I've probably used the wrong terms, but by physical path I mean for example "d:\inetpub\wwwroot\index.htm". If I have a ftp-login that starts in wwwroot, the ftp_pwd() would not return the whole path, or am I wrong?

0
 
LVL 3

Expert Comment

by:thecode101
ID: 11727455
Correct if your ftp user starts in wwwroot, ftp_pwd() will not return the whole path, but if you set the ftp login to start in d:\ it will return the whole path.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11727456
ftp_pwd does return physical directory, by example:

/var/apache/yourassigneddir/
0
 

Author Comment

by:speder
ID: 11727513
Ok - so if I start in wwwroot is there a way to get the whole physical path anyway (the whole d:\inetpub\wwwroot)?

If not, I guess I would have to upload a asp-script to the server (this only targets iis-servers) and then afterwards read the script and see what it returns.
0
 
LVL 3

Expert Comment

by:thecode101
ID: 11727699
If the php command ftp_raw is working on the server you could try something like
ftp_raw ($conn_id,'pwd')
But I have not tested this because the function does not work with my version of php.

http://us2.php.net/manual/en/function.ftp-raw.php
0
 

Author Comment

by:speder
ID: 11754238
This piece of code return the correct top folder list og files and folders for both linux- and windows server. I don't know if this can help:

<?php
$conn_id = ftp_connect("ftp.xxx.com");
$login_result = ftp_login($conn_id, "yyy", "zzz");
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
die;
} else {
echo "Connected";
}
$contents = ftp_nlist($conn_id, ".");
echo implode($contents,"/");
ftp_quit($conn_id);
?>
0
 

Author Comment

by:speder
ID: 11754290
ups - wrong place.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question