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
Solved

Find the physical path of file

Posted on 2004-08-04
10
568 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
  • 5
  • 3
  • 2
10 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 70 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 30 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 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