/** * @param string $mode * @param string $path * @param bool $recursive * * @return bool */ public function chmod($mode, $path, $recursive = false) { switch ($this->_connType) { case SftpHelper::TYPE_SFTP: default: $res = $this->_connection->chmod($mode, $path, $recursive); break; case SftpHelper::TYPE_FTP: if ($recursive) { Console::stdout("\n"); Log::throwException('Recursive not supported for chmod in ftp mode'); } $res = @ftp_chmod($this->_connection, $mode, $path); break; } return $res; }
public function mkdir($dir) { return $this->ftp->mkdir($dir) && $this->ftp->chmod($this->permDir, $dir); }
/** * Chamge mode of a directory or a file * */ public function chmod($filename, $mode) { return $this->_connection->chmod($mode, $filename); }
//ssh connect to cr2g server $ssh = new Net_SSH2('cr2g01.cs.utep.edu', 22); if (!$ssh->login('rlgruver', 'utep$2015')) { exit('ssh Login Failed'); } //attempted to set an ssh timeout, not allowed on UTEP server $ssh->setTimeout(7200); //sftp connect to cr2g server $sftp = new Net_SFTP('cr2g01.cs.utep.edu', 22); if (!$sftp->login('rlgruver', 'utep$2015')) { exit('sftp Login Failed'); } //send input file to cr2g server $sftp->mkdir('/code/spopt-stable/tests/' . $session); $sftp->put($remoteInputFile, $localInputFile, NET_SFTP_LOCAL_FILE); $sftp->chmod(0777, $remoteInputFile); //execute python script in this order to run the Solver: //1. change to directory where solver script is located $ssh->write("cd /code/spopt-stable\n"); //2. 'read' command to ensure script is called from the proper directory $ssh->read('rlgruver@cr2g01:/code/spopt-stable$'); //3. run the solver script with the test from the current session $ssh->write("python SpOpt.py tests/" . $session . "/input.txt\n"); //start timerin case anything gets stuck, will break within 120 minutes (7200 sec) $starttime = time(); //ssh will break within 120 minutes (7200 sec) regardless of execution status while ($ssh->isConnected()) { $now = time() - $starttime; if ($now > 7200) { break; }
/** * This method is called to set metadata on the stream. It is called when one of the following functions is called on a stream URL: * - touch() * - chmod() * - chown() * - chgrp() * * Changes stream options * * @param String $path * @param Integer $option * @param mixed $var * @return bool * @access public */ public function stream_metadata($path, $option, $var) { $connection = $this->stream_open($path, NULL, NULL, $opened_path); if ($connection === false) { return FALSE; } switch ($option) { case 1: // PHP_STREAM_META_TOUCH $touch = $this->sftp->touch($this->path, $var[1], $var[0]); $this->stream_close(); return $touch; case 2: // PHP_STREAM_META_OWNER_NAME $this->stream_close(); return FALSE; case 3: // PHP_STREAM_META_OWNER $chown = $this->sftp->chown($this->path, $var); $this->stream_close(); return $chown; case 4: // PHP_STREAM_META_GROUP_NAME $this->stream_close(); return FALSE; case 5: // PHP_STREAM_META_GROUP $chgrp = $this->sftp->chgrp($this->path, $var); $this->stream_close(); return $chgrp; case 6: // PHP_STREAM_META_ACCESS $chmod = $this->sftp->chmod($var, $this->path); $this->stream_close(); return $chmod; default: $this->stream_close(); return FALSE; } }
private function executeLinux() { if (strlen($this->shellScripts['user']) > 0 or count($this->shellScripts['server']) > 0) { $sftpObject = new Net_SFTP($this->appMasterServerDetails['ssh2IP'], $this->appMasterServerDetails['ssh2Port']); $ssh2Pass = $this->getKeyAndOrPassword(); $loginReturn = $sftpObject->login($this->appMasterServerDetails['ssh2User'], $ssh2Pass); if ($loginReturn) { $this->commandReturns[] = $sftpObject->put('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/userCud-' . $this->uniqueHex . '.sh', $this->shellScripts['user']); $this->commandReturns[] = $sftpObject->chmod(0700, '/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/userCud-' . $this->uniqueHex . '.sh'); foreach ($this->shellScripts['server'] as $fileName => $scriptContent) { $this->commandReturns[] = 'script added: ' . $fileName; $this->commandReturns[] = $sftpObject->put($fileName, $scriptContent); } // Files have been created, now login with SSH2 and execute the gobal script $sshObject = new Net_SSH2($this->appMasterServerDetails['ssh2IP'], $this->appMasterServerDetails['ssh2Port']); if ($sshObject->login($this->appMasterServerDetails['ssh2User'], $ssh2Pass)) { $this->commandReturns[] = $sshObject->exec('/home/' . $this->appMasterServerDetails['ssh2User'] . '/temp/userCud-' . $this->uniqueHex . '.sh & '); } return true; } $this->handleFailedConnectAttemps(); } return false; }
private function linuxSshConnectAndExecute($updating, $getReturn, $ssh2Pass) { $sftpObject = new Net_SFTP($this->sship, $this->sshport); $loginReturn = $sftpObject->login($this->sshuser, $ssh2Pass); if ($loginReturn) { $sftpObject->put('/home/' . $this->sshuser . '/temp/master-' . $this->uniqueHex . '.sh', $this->shellScript); $sftpObject->chmod(0700, '/home/' . $this->sshuser . '/temp/master-' . $this->uniqueHex . '.sh'); // File has been created, now login with SSH2 and execute the script $sshObject = new Net_SSH2($this->sship, $this->sshport); if ($sshObject->login($this->sshuser, $ssh2Pass)) { if ($updating === true) { $this->setUpdating(); $removeLogs = $this->removeUpdateLogs(); if ($removeLogs !== false) { $sftpObject->put('/home/' . $this->sshuser . '/temp/remove-update-logs-' . $this->uniqueHex . '.sh', $removeLogs); $sftpObject->chmod(0700, '/home/' . $this->sshuser . '/temp/remove-update-logs-' . $this->uniqueHex . '.sh'); $sshObject->exec('/home/' . $this->sshuser . '/temp/remove-update-logs-' . $this->uniqueHex . '.sh & '); } } if ($getReturn === false) { $sshObject->exec('/home/' . $this->sshuser . '/temp/master-' . $this->uniqueHex . '.sh & '); return true; } return $sshObject->exec('/home/' . $this->sshuser . '/temp/master-' . $this->uniqueHex . '.sh'); } } return false; }
$remote_sauce = "/home/" . $_POST['username'] . "/sauce/"; $remote_sauce_src = "/home/" . $_POST['username'] . "/sauce/src/"; $remote_location = $remote_sauce_src . $ctinfo[1]; $file_size = filesize($build_location); if (file_exists($build_location)) { $sftp = new Net_SFTP($sinfo[0]); $key = new Crypt_RSA(); $key->loadKey(file_get_contents($sshkey_location)); if (!$sftp->login('root', $key)) { $error[] = "Login Failed"; } else { $debug[] = $sftp->mkdir($remote_sauce); $debug[] = $sftp->mkdir($remote_sauce_src); $debug[] = $sftp->put($remote_location, $file_size); $debug[] = $sftp->put($remote_location, $build_location, NET_SFTP_LOCAL_FILE); $debug[] = $sftp->chmod(0755, $remote_location); echo "Daemon uploaded!"; } } else { //if file doesnt exist, check in the database to see if we can borrow from another server ;) $error[] = "Unable to find coind file in the /builds folder."; } print_r($debug); print_r($error); echo ' <form action=coinds.add-do.step5.php method=post> <input type=hidden name=templateid value="' . $_POST['templateid'] . '" /> <input type=hidden name=serverid value="' . $_POST['serverid'] . '" /> <input type=hidden name=username value="' . $_POST['username'] . '" /> <input type=hidden name=rpc_user value="' . $_POST['rpc_user'] . '" /> <input type=hidden name=rpc_password value="' . $_POST['rpc_password'] . '" />