kumar
kumar

Reputation: 1826

What is the ftp_chdir equivalent in SFTP?

I am working on SFTP section (in PHP). I know the function to change the directory after making the connection in FTP which is ftp_chdir.

What is the similar function in SFTP?

Is ssh2_sftp_readlink the similar one?

Upvotes: 2

Views: 2496

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202494

The SFTP protocol does not have a concept of a working directory you know from the FTP protocol (or a local system).

So there's no equivalent.


Some SFTP libraries (and probably all SFTP clients) can simulate the working directory locally. But PHP SSH2 library cannot.

For example, another PHP SFTP implementation, the phpseclib has SFTP::chdir method.


In general with SFTP you should use absolute paths. Most SFTP servers also allows you to use relative paths to the account's home directory.

You may find also function ssh2_sftp_realpath useful to convert a relative path to an absolute path.

The ssh2_sftp_realpath(".") should return an absolute path to the home directory.

Upvotes: 4

Related Questions