ensure the directory exists before upload a file in native ssh

This commit is contained in:
oscarotero 2016-11-21 21:28:44 +01:00
parent 43c7ef9a84
commit 5c2fcfef5f

View File

@ -13,6 +13,11 @@ use Symfony\Component\Process\Process;
class NativeSsh implements ServerInterface
{
/**
* @var array
*/
private $mkdirs = [];
/**
* @var Configuration
*/
@ -43,7 +48,6 @@ class NativeSsh implements ServerInterface
$sshOptions = [
'-A',
'-q',
'-r',
'-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
];
@ -82,6 +86,13 @@ class NativeSsh implements ServerInterface
$username = $serverConfig->getUser() ? $serverConfig->getUser() : null;
$hostname = $serverConfig->getHost();
$dir = dirname($remote);
if (!in_array($dir, $this->mkdirs)) {
$this->run('mkdir -p ' . escapeshellarg($dir));
$this->mkdirs[] = $dir;
}
return $this->scpCopy($local, (!empty($username) ? $username . '@' : '') . $hostname . ':' . $remote);
}