开发者

Using ftp_*, how could I determine the public html directory?

开发者 https://www.devze.com 2023-01-04 03:14 出处:网络
If I don\'t know the public开发者_如何学编程 web directory, is there a way my script could determine the web directory, so that the script would know which directory to upload the file to?

If I don't know the public开发者_如何学编程 web directory, is there a way my script could determine the web directory, so that the script would know which directory to upload the file to?


If I don't know the public web directory, is there a way my script could determine the web directory, so that the script would know which directory to upload the file to?

If you are talking about determining the web root of a remote host that you are connecting to using FTP, the answer is no, definitely not.

The FTP account you are using to log on can have a root setting completely different from what Virtual host(s) are configured on the server. They have nothing to do with each other, and no way to interact.

There will usually be some overlap (e.g. the FTP directory being something like /htdocs/domain.com/ but there is no pattern you could rely on.


Do you want a "commercially feasible" approach, or do you want to learn? This answer is for the second case :)

You could upload a file with a special name (for example, fjskjfakdjfklajf.txt) via FTP (your PHP script could probably do that too, for example with some curl calls). Then you can run another PHP script which will try to traverse the file system, and look for the file. You will need list the contents of each directory (see opendir) and check for each entry if it is a directory, or a file. If it is a file, and it is your file, then you have fond the FTP root. You will probably have a limited access to the server, so the search action will probably not last too much time. You can start from the current directory your script is in, try to descend to each directory, then move to '..'

Your current directory is: $currentDir = dirname(FILE);


Do you wan't to know the document root of the machine the script is running? In that case, just use $_SERVER['DOCUMENT_ROOT'].

I'm not sure how to receive such info from a remote host (if that's possible at all)


Rob -

Do you only have access to the server via FTP?

Do you have already have access to the web root (or a way to add php scripts), but want to know they fully qualified path?

If the answer to the second question is yes, you can do what @Treur suggested, and install a php script that returns the value of DOCUMENT_ROOT, then use that from your FTP client.

I guess knowing exactly what you're trying to do, and what the situation is, would help. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消