I have the following function in my model:
public function createfolder($location, $name){
define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
$sftp = new Net_SFTP('xx.xxx.xx.xx');
if (!$sftp->login('admin', '********')) {
exit('Login Failed');
}
//moves to a location (Job folder for example)
$sftp->chdir($location);
//makes the folder
$sftp->mkdir($name);
}
This will work but I would like to add some sort of error prevention validation, how can I check if a folder exists using SFTP?
Think I came up with a solution:
chdir()
changes directories,mkdir()
creates directories, andrmdir()
removes directories. In the event of failure, they all returnfalse
.chdir()
,mkdir()
, andrmdir()
returntrue
on successful completion of the operation.
So I can use an if
statement to check if chdir() === true
or false
to see if the directory is there.