Related to: #9129
The `remoteDirectoryPath` might be `null`, so it is not correct to attempt `remoteDirectoryPath.charAt(0)`.
Plus `/null` is not correct path.
* Use `/` for empty remote dir.
* Check for `remoteDirectoryPath != null`
(cherry picked from commit 467c96171e)