[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

Find the physical path of file

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
speder
Asked:
speder
  • 5
  • 3
  • 2
2 Solutions
 
Jaime OlivaresCommented:
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
 
spederAuthor Commented:
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
 
thecode101Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
spederAuthor Commented:
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
 
thecode101Commented:
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
 
Jaime OlivaresCommented:
ftp_pwd does return physical directory, by example:

/var/apache/yourassigneddir/
0
 
spederAuthor Commented:
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
 
thecode101Commented:
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
 
spederAuthor Commented:
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
 
spederAuthor Commented:
ups - wrong place.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now