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()returntrueon 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.
You can use $sftp->is_dir($location) to check if it's a directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With