I am connecting to remote sftp server using ssh2 functions. Now I need to get current directory name. In case of ftp server I can use ftp_pwd but I can't find similar function for ssh2
I need php code
I am connecting to remote sftp server using ssh2 functions. Now I need to get current directory name. In case of ftp server I can use ftp_pwd but I can't find similar function for ssh2
I need php code
Give phpseclib
a try for sftp
connections, you can do easily get the current working dir with its built-in method pwd
From the directory management examples:
print $sftp->pwd();
Have you tried only pwd ? Type help for list of available commands
On Ubuntu 20.04 SFTP server ssh2_sftp_realpath
returns the same as running pwd
interactively
<?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
?>