Does the phpseclib delete function supports wildcard character ? If not, any alternatives ?
Not at present no. I guess you could do $sftp->nlist()
and do a preg_match on each row returned by nlist. If it matches delete it, otherwise keep it.
Question
I tried to use phpseclib to delete all logs in SFTP server.
Codes are simple:
$sftp = new Net_SFTP($host_name);
$sftp->login($username, $password); // login is successful
$sftp->chdir('/somefolder');
if(!$sftp->delete('*.log')) {
$logger->error('Cannot remove logs');
}
The log shows "Cannot remove logs".
However, I use SFTP command in shell, it works :
$ sftp myusername@example.com
Password: (type in my password)
sftp> cd /somefolder
sftp> rm *.log
Removing xxx.log
Removing yyy.log
sftp> ls
( no more *.log )
sftp> exit
Does the phpseclib delete function supports wildcard character ? If not, any alternatives ?
Solution
Does the phpseclib delete function supports wildcard character ? If not, any alternatives ?
Not at present no. I guess you could do $sftp->nlist()
and do a preg_match on each row returned by nlist. If it matches delete it, otherwise keep it.