繁体   English   中英

如何从sftp服务器获取当前目录名

[英]How to get current directory name from sftp server

我正在使用 ssh2 函数连接到远程 sftp 服务器。 现在我需要获取当前目录名称。 如果是 ftp 服务器,我可以使用 ftp_pwd 但我找不到类似的 function 用于 ssh2

我需要 php 代码

尝试phpseclib进行sftp连接,您可以使用其内置方法pwd轻松获得当前的工作目录

目录管理示例:

print $sftp->pwd();

您是否只尝试了密码? 键入帮助以获取可用命令列表

在 Ubuntu 20.04 SFTP 服务器ssh2_sftp_realpath返回与交互式运行pwd相同

<?php
$connection = ssh2_connect('host.example.com', 22);

ssh2_auth_password($connection, 'sftptest', 'password');

$sftp = ssh2_sftp($connection);

$realpath = ssh2_sftp_realpath($sftp, '.');

# $realpath is now: '/home/sftptest'

$realpath = ssh2_sftp_realpath($sftp, './test');

# $realpath =  /home/sftptest/test

$realpath = ssh2_sftp_realpath($sftp, "../test2");

# $realpath = /home/test2

# note that the directories don't have to exist it just resolves to what it should be based on the current directory
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM