Solved

Find the physical path of file

Posted on 2004-08-04
10
552 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:speder
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
ftp_pwd does return physical directory, by example:

/var/apache/yourassigneddir/
0
 

Author Comment

by:speder
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
ups - wrong place.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now