Title: WP_Filesystem_SSH2::sftp_path
Published: December 9, 2015
Last modified: February 24, 2026

---

# WP_Filesystem_SSH2::sftp_path( string $path ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#wp--skip-link--target)

Gets the ssh2.sftp PHP stream wrapper path to open for the given file.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#description)󠁿

This method also works around a PHP bug where the root directory (/) cannot be opened
by PHP functions, causing a false failure. In order to work around this, the path
is converted to /./ which is semantically the same as / See [https://bugs.php.net/bug.php?id=64169](https://bugs.php.net/bug.php?id=64169)
for more details.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#parameters)󠁿

 `$path`stringrequired

The File/Directory path on the remote server to return

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#return)󠁿

 string The ssh2.sftp:// wrapped path to use.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#source)󠁿

    ```php
    public function sftp_path( $path ) {
    	if ( '/' === $path ) {
    		$path = '/./';
    	}

    	return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-wp-filesystem-ssh2.php#L200)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-filesystem-ssh2.php#L200-L206)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Filesystem_SSH2::exists()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/exists/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Checks if a file or directory exists.

  | 
| [WP_Filesystem_SSH2::is_file()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/is_file/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Checks if resource is a file.

  | 
| [WP_Filesystem_SSH2::is_dir()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/is_dir/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Checks if resource is a directory.

  | 
| [WP_Filesystem_SSH2::is_readable()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/is_readable/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Checks if a file is readable.

  | 
| [WP_Filesystem_SSH2::atime()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/atime/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file’s last access time.

  | 
| [WP_Filesystem_SSH2::mtime()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/mtime/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file modification time.

  | 
| [WP_Filesystem_SSH2::size()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/size/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file size (in bytes).

  | 
| [WP_Filesystem_SSH2::dirlist()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/dirlist/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets details for files in a directory or a specific file.

  | 
| [WP_Filesystem_SSH2::get_contents()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/get_contents/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Reads entire file into a string.

  | 
| [WP_Filesystem_SSH2::get_contents_array()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/get_contents_array/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Reads entire file into an array.

  | 
| [WP_Filesystem_SSH2::put_contents()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/put_contents/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Writes a string to a file.

  | 
| [WP_Filesystem_SSH2::owner()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/owner/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file owner.

  | 
| [WP_Filesystem_SSH2::getchmod()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/getchmod/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the permissions of the specified file or filepath in their octal format.

  | 
| [WP_Filesystem_SSH2::group()](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/group/)`wp-admin/includes/class-wp-filesystem-ssh2.php` |

Gets the file’s group.

  |

[Show 9 more](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_filesystem_ssh2/sftp_path/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_filesystem_ssh2%2Fsftp_path%2F)
before being able to contribute a note or feedback.