Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * 
  * @see \mithra62\Validate\RuleInterface::validate()
  * @ignore
  *
  */
 public function validate($field, $input, array $params = array())
 {
     try {
         if ($input == '' || empty($params['0'])) {
             return false;
         }
         $params = $params['0'];
         if (empty($params['sftp_host']) || empty($params['sftp_port']) || empty($params['sftp_root'])) {
             return false;
         }
         // we require either a private key file OR a username and password
         if (empty($params['sftp_password']) && empty($params['sftp_username']) && empty($params['sftp_private_key'])) {
             return false;
         }
         $filesystem = new Remote(Sftp::getRemoteClient($params));
         $return = true;
         $filesystem->getAdapter()->listContents();
         if (!$filesystem->getAdapter()->isConnected()) {
             $return = false;
         }
         $filesystem->getAdapter()->disconnect();
         return $return;
     } catch (\Exception $e) {
         return false;
     }
 }
Esempio n. 2
0
 /**
  * (non-PHPdoc)
  * 
  * @see \mithra62\Validate\RuleInterface::validate()
  * @ignore
  *
  */
 public function validate($field, $input, array $params = array())
 {
     try {
         if ($input == '' || empty($params['0'])) {
             return false;
         }
         $params = $params['0'];
         if (empty($params['sftp_host']) || empty($params['sftp_password']) || empty($params['sftp_username']) || empty($params['sftp_port']) || empty($params['sftp_root'])) {
             return false;
         }
         $local = new Remote(new Local(dirname($this->getTestFilePath())));
         $filesystem = new Remote(Sftp::getRemoteClient($params));
         if ($local->has($this->test_file)) {
             $contents = $local->read($this->test_file);
             $filesystem->getAdapter()->setRoot($params['sftp_root']);
             if ($filesystem->has($this->test_file)) {
                 $filesystem->delete($this->test_file);
             } else {
                 if ($filesystem->write($this->test_file, $contents)) {
                     $filesystem->delete($this->test_file);
                 }
             }
         }
         $filesystem->getAdapter()->disconnect();
         return true;
     } catch (\Exception $e) {
         return false;
     }
 }
Esempio n. 3
0
 public function testGetRemoteClient()
 {
     $settings = $this->getSftpCreds();
     $this->assertInstanceOf('\\League\\Flysystem\\AdapterInterface', Sftp::getRemoteClient($settings));
 }