Exemple #1
0
function DeleteUpfile($R, $d)
{
    global $g, $table;
    $UPFILES = getArrayString($R['upload']);
    foreach ($UPFILES['data'] as $_val) {
        $U = getUidData($table['s_upload'], $_val);
        if ($U['uid']) {
            if ($U['url'] == $d['comment']['ftp_urlpath']) {
                $FTP_CONNECT = ftp_connect($d['comment']['ftp_host'], $d['comment']['ftp_port']);
                $FTP_CRESULT = ftp_login($FTP_CONNECT, $d['comment']['ftp_user'], $d['comment']['ftp_pass']);
                if ($d['comment']['ftp_pasv']) {
                    ftp_pasv($FTP_CONNECT, true);
                }
                if (!$FTP_CONNECT) {
                    getLink('', '', 'FTP서버 연결에 문제가 발생했습니다.', '');
                }
                if (!$FTP_CRESULT) {
                    getLink('', '', 'FTP서버 아이디나 패스워드가 일치하지 않습니다.', '');
                }
                ftp_delete($FTP_CONNECT, $d['comment']['ftp_folder'] . $U['folder'] . '/' . $U['tmpname']);
                if ($U['type'] == 2) {
                    ftp_delete($FTP_CONNECT, $d['comment']['ftp_folder'] . $U['folder'] . '/' . $U['thumbname']);
                }
                ftp_close($FTP_CONNECT);
            } else {
                unlink($U['url'] . $U['folder'] . '/' . $U['tmpname']);
                if ($U['type'] == 2) {
                    unlink($U['url'] . $U['folder'] . '/' . $U['thumbname']);
                }
            }
            getDbDelete($table['s_upload'], 'uid=' . $U['uid']);
        }
    }
}
 public function xmlFtpTest($xmlFileID)
 {
     $ftp_server = "117.55.235.145";
     $conn_id = ftp_connect($ftp_server);
     $ftp_user_name = "s1057223";
     $ftp_user_pass = "******";
     // login with username and password
     $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
     // check connection
     if (!$conn_id || !$login_result) {
         // echo "FTP connection has failed!";
         // echo "Attempted to connect to $ftp_server for user $ftp_user_name";
         // exit;
     } else {
         // echo "Connected to $ftp_server, for user $ftp_user_name";
     }
     $target_dir = public_path('assets/data/');
     $destination_file = "/public_html/test1/" . $xmlFileID . ".xml";
     $source_file = $target_dir . $xmlFileID . ".xml";
     // upload the file
     $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
     // check upload status
     if (!$upload) {
         echo "FTP upload has failed!";
     } else {
         // echo "Uploaded $source_file to $ftp_server as $destination_file";
     }
     // close the FTP stream
     ftp_close($conn_id);
 }
function ftp_put_file($remote, $local)
{
    $ftp_host = 'xungeng.vpaas.net';
    $ftp_user = '******';
    $ftp_pass = '******';
    $code = 0;
    $conn_id = ftp_connect($ftp_host);
    if ($conn_id) {
        // try to login
        $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
        if ($login_result) {
            $source_file = $local;
            //源地址
            $destination_file = $remote;
            //目标地址
            $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
            if ($upload) {
                $msg = "success";
                $code = 1;
            } else {
                $msg = "FTP upload has failed!";
            }
        } else {
            $msg = "FTP connection has failed!" . "Attempted to connect to {$ftp_host} for user {$ftp_user}";
        }
    } else {
        $msg = "无法连接到{$ftp_host}";
    }
    ftp_close($conn_id);
    return array('code' => $code, 'msg' => $msg);
}
Exemple #4
0
 public function close()
 {
     if ($this->connected) {
         return ftp_close($this->handle);
     }
     return false;
 }
function JSX_PHP_FTP_Directory_List_Get($p_aConnData, $p_aPathData)
{
    // Connection settings.
    $hostname = $p_aConnData['hostname'];
    $username = $p_aConnData['username'];
    $password = $p_aConnData['password'];
    // Directory settings.
    $startdir = $p_aPathData['startdir'];
    // absolute path
    $suffix = $p_aPathData['suffix'];
    // suffixes to list
    $g_levello = $p_aPathData['levello'];
    // Livello di "nested directory".
    // Data array.
    $files = array();
    // Ftp connection.
    $conn_id = ftp_connect($hostname);
    $login = ftp_login($conn_id, $username, $password);
    if (!$conn_id) {
        echo 'Wrong server!';
        exit;
    } else {
        if (!$login) {
            echo 'Wrong username/password!';
            exit;
        } else {
            // Get data through FTP.
            $files = JSX_PHP_FTP_raw_list($conn_id, $p_aConnData, $p_aPathData, $files);
        }
    }
    // Close FTP connection.
    ftp_close($conn_id);
    // Return value.
    return $files;
}
Exemple #6
0
function ftpBackupFile($source_file, $ftpserver, $ftpuser, $ftppassword)
{
    global $log;
    $FTPOK = 0;
    $NOCONNECTION = 1;
    $NOLOGIN = 2;
    $NOUPLOAD = 3;
    $log->debug("Entering ftpBackupFile(" . $source_file . ", " . $ftpserver . ", " . $ftpuser . ", " . $ftppassword . ") method ...");
    // set up basic connection
    $conn_id = @ftp_connect($ftpserver);
    if (!$conn_id) {
        $log->debug("Exiting ftpBackupFile method ...");
        return $NOCONNECTION;
    }
    // login with username and password
    $login_result = @ftp_login($conn_id, $ftpuser, $ftppassword);
    if (!$login_result) {
        ftp_close($conn_id);
        $log->debug("Exiting ftpBackupFile method ...");
        return $NOLOGIN;
    }
    // upload the file
    $destination_file = basename($source_file);
    $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
    // check upload status
    if (!$upload) {
        ftp_close($conn_id);
        $log->debug("Exiting ftpBackupFile method ...");
        return $NOUPLOAD;
    }
    // close the FTP stream
    ftp_close($conn_id);
    $log->debug("Exiting ftpBackupFile method ...");
    return $FTPOK;
}
Exemple #7
0
 function test_connection()
 {
     if ($this->input->is_ajax_request()) {
         header('Content-Type: application/json', true);
         $ftp_server = trim($this->input->post('address'));
         $ftp_user = trim($this->input->post('user'));
         $ftp_password = trim($this->input->post('password'));
         $port = trim($this->input->post('port'));
         // set up basic connection
         if ($this->input->post('SFTP') == true) {
             $conn_id = @ftp_ssl_connect($ftp_server, $port) or die(json_encode(array('status' => 'error', 'output' => '<span class="delete ftp-alert cmsicon" style="display: inline-block;float: none;"></span>&nbsp;Couldn\'t connect to ' . $ftp_server)));
         } else {
             $conn_id = @ftp_connect($ftp_server, $port) or die(json_encode(array('status' => 'error', 'output' => '<span class="delete ftp-alert cmsicon" style="display: inline-block;float: none;"></span>&nbsp;Couldn\'t connect to ' . $ftp_server)));
         }
         // login with username and password
         if (!@ftp_login($conn_id, $ftp_user, $ftp_password)) {
             $output = array('status' => 'error', 'output' => '<span class="cus-cross-octagon"></span>&nbsp;Username and Password is incorrect');
         } else {
             $output = array('status' => 'success', 'output' => '<span class="cus-accept"></span>&nbsp;Connection OK!');
         }
         ftp_close($conn_id);
         echo json_encode($output);
     } else {
         show_404();
     }
 }
Exemple #8
0
 /**
  * Closes an FTP connection
  * 
  * @return boolean Returns true on success or false on failure
  */
 public function close()
 {
     $result = ftp_close($this->connection);
     $this->connection = null;
     $this->loggedIn = false;
     return $result;
 }
 /**
  * Tries to logon to the FTP server with given id and password
  *
  * @access public
  *
  * @param  string $source Authentication source to be used 
  * @param  string $external_uid    The ID entered
  * @param  string $external_passwd The password of the user
  *
  * @return boolean  True if the authentication was a success, false 
  *                  otherwise
  */
 public function Authenticate($source, $external_uid, $external_passwd)
 {
     $enc = ExternalAuthenticator::getAuthEnc($source);
     $port = ExternalAuthenticator::getAuthPort($source);
     if (is_null($port)) {
         $port = self::$port;
     }
     ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connecting to ' . ExternalAuthenticator::getAuthServer($source) . ' port ' . $port);
     if ($enc == 'ssl') {
         ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connection type is SSL');
         $conn = @ftp_ssl_connect(ExternalAuthenticator::getAuthServer($source), $port);
     } else {
         $conn = @ftp_connect(ExternalAuthenticator::getAuthServer($source), $port);
     }
     if (!$conn) {
         ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connection to server failed');
         ExternalAuthenticator::setAuthMessage(_t('FTP_Authenticator.NoConnect', 'Could not connect to FTP server'));
         return false;
     } else {
         ExternalAuthenticator::AuthLog($external_uid . '.ftp - Connection to server succeeded');
     }
     if (!@ftp_login($conn, $external_uid, $external_passwd)) {
         ExternalAuthenticator::AuthLog($external_uid . '.ftp - User credentials failed at ftp server');
         ftp_close($conn);
         ExternalAuthenticator::setAuthMessage(_t('ExternalAuthenticator.Failed'));
         return false;
     } else {
         ExternalAuthenticator::AuthLog($external_uid . '.ftp - ftp server validated credentials');
         ftp_close($conn);
         return true;
     }
 }
Exemple #10
0
 public function generate($log)
 {
     global $db;
     $host = "ftp.mozilla.org";
     $hostpos = strpos($this->logURL, $host);
     if ($hostpos === false) {
         throw new Exception("Log file {$this->logURL} not hosted on {$host}!");
     }
     $path = substr($this->logURL, $hostpos + strlen($host) + strlen("/"));
     $ftpstream = @ftp_connect($host);
     if (!@ftp_login($ftpstream, "anonymous", "")) {
         throw new Exception("Couldn't connect to Mozilla FTP server.");
     }
     $fp = tmpfile();
     if (!@ftp_fget($ftpstream, $fp, $path, FTP_BINARY)) {
         throw new Exception("Log not available at URL {$this->logURL}.");
     }
     ftp_close($ftpstream);
     rewind($fp);
     $db->beginTransaction();
     $stmt = $db->prepare("\n      UPDATE runs_logs\n      SET content = :content\n      WHERE buildbot_id = :id AND type = :type;");
     $stmt->bindParam(":content", $fp, PDO::PARAM_LOB);
     $stmt->bindParam(":id", $log['_id']);
     $stmt->bindParam(":type", $log['type']);
     $stmt->execute();
     $db->commit();
     fclose($fp);
 }
function ftpMkDir($path, $newDir, $ftpServer, $ftpUser, $ftpPass)
{
    $server = $ftpServer;
    // ftp server
    $connection = ftp_connect($server);
    // connection
    // login to ftp server
    $user = $ftpUser;
    $pass = $ftpPass;
    $result = ftp_login($connection, $user, $pass);
    // check if connection was made
    if (!$connection || !$result) {
        return false;
        exit;
    } else {
        ftp_chdir($connection, $path);
        // go to destination dir
        if (ftp_mkdir($connection, $newDir)) {
            // create directory
            return $newDir;
        } else {
            return false;
        }
        ftp_close($connection);
        // close connection
    }
}
Exemple #12
0
 public function __destruct()
 {
     if ($this->_ftpStream) {
         // close FTP connection
         @ftp_close($this->_ftpStream);
     }
 }
Exemple #13
0
 static function ftp_image_close()
 {
     if (ImageLib::$ftp_image_connect_id) {
         ftp_close(ImageLib::$ftp_image_connect_id);
         ImageLib::$ftp_image_connect_id = false;
     }
 }
Exemple #14
0
 /**
  * Function that retrieves a file from FTP library and compress it if necessary
  * 
  * @param string $file File name to be retrieved from FTP library
  * @return boolean
  */
 public function get_file($file, $dir = '')
 {
     if (!defined("LOCATION") || !defined("CODE") || !defined("LIBRARY") || !defined("CACHE_PATH")) {
         $this->container->__error("Imposible recuperar el archivo remoto: falta alguna constante por definir");
         return false;
     }
     $cnn = ftp_connect(LOCATION);
     $rs = ftp_login($cnn, LIBRARY, CODE);
     if ($rs === false) {
         $this->container->__error("Imposible conectar a la libreria de funciones!");
     }
     $dir = $dir == '' ? '' : $dir . DIRECTORY_SEPARATOR;
     ftp_chdir($cnn, LIBRARY . DIRECTORY_SEPARATOR . $dir);
     if (@ftp_chdir($cnn, $file) !== false) {
         if ($this->container->__debug()) {
             @mkdir(CACHE_PATH . $dir . $file);
             chmod(CACHE_PATH . $dir . $file, 0777);
             $dir = $dir == '' ? $file : $dir . $file;
         } else {
             @mkdir(CACHE_PATH . $dir . md5($file));
             chmod(CACHE_PATH . $dir . md5($file), 0777);
             $dir = $dir == '' ? $file : $dir . $file;
         }
         $files = ftp_nlist($cnn, ".");
         foreach ($files as $filea) {
             $this->get_file($filea, $dir);
         }
         return true;
     } else {
         if ($file == '.' || $file == '..') {
             return;
         }
         if ($this->container->__debug()) {
             $aux = ftp_get($cnn, CACHE_PATH . $dir . $file, $file, FTP_BINARY);
         } else {
             $temp = explode(DIRECTORY_SEPARATOR, $dir);
             array_walk($temp, function (&$element, $index) {
                 $element = md5($element);
             });
             array_pop($temp);
             $temp = implode(DIRECTORY_SEPARATOR, $temp) . DIRECTORY_SEPARATOR;
             $aux = ftp_get($cnn, CACHE_PATH . $temp . md5($file), $file, FTP_BINARY);
         }
         if (!$aux) {
             ftp_close($cnn);
             $this->container->__error("Imposible obtener el archivo para cache: " . $file);
             return false;
         } else {
             ftp_close($cnn);
             if ($this->container->__debug()) {
                 chmod(CACHE_PATH . $dir . $file, 0777);
                 $this->compress_cache_file($dir . $file);
             } else {
                 chmod(CACHE_PATH . $temp . md5($file), 0777);
                 $this->compress_cache_file($temp . md5($file));
             }
             return true;
         }
     }
 }
Exemple #15
0
function subida_script($ftp_server, $ftp_user, $ftp_pass)
{
    // set up basic connection
    $conn_id = ftp_connect($ftp_server);
    if (!$conn_id) {
        echo "<div class='alert alert-warning' style='width:300px;margin:auto'>Connection established</div>";
    }
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
    if ($login_result) {
        echo "<div class='alert alert-success' style='width:300px;margin:auto'>Connection established</div>";
    }
    ftp_chdir($conn_id, 'public_html');
    ftp_mkdir($conn_id, 'search');
    ftp_chdir($conn_id, 'search');
    ftp_mkdir($conn_id, 'css');
    ftp_chdir($conn_id, 'css');
    echo ftp_pwd($conn_id);
    ftp_chdir($conn_id, '../../autotienda/search');
    echo ftp_pwd($conn_id);
    //Uploading files...
    //to be uploaded
    $file = "search/.htaccess";
    $fp = fopen($file, 'r');
    ftp_fput($conn_id, $file, $fp, FTP_ASCII);
    echo ftp_pwd($conn_id);
    // close the connection
    ftp_close($conn_id);
    fclose($fp);
}
Exemple #16
0
 /**
  * Reconnects to FTP server.
  * @return void
  */
 public function reconnect()
 {
     @ftp_close($this->resource);
     foreach ($this->state as $name => $args) {
         call_user_func_array(array($this, $name), $args);
     }
 }
Exemple #17
0
 public function downloadFile()
 {
     $requestURL = trim(Mage::getStoreConfig('pulliver/western_power/base_url'), ' /');
     $username = Mage::getStoreConfig('pulliver/western_power/username');
     $password = Mage::getStoreConfig('pulliver/western_power/password');
     $connection = ftp_connect($requestURL);
     if (!$connection) {
         Vikont_Pulliver_Helper_Data::inform(sprintf('Could not connect to %s', $requestURL));
     }
     if (!@ftp_login($connection, $username, $password)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('Error logging to FTP %s as %s', $requestURL, $username));
     }
     $remoteFileName = Mage::getStoreConfig('pulliver/western_power/remote_filename');
     $localFileName = $this->getLocalFileName($remoteFileName, 'downloaded/');
     if (file_exists($localFileName)) {
         @unlink($localFileName);
     } else {
         if (!file_exists($dirName = dirname($localFileName))) {
             mkdir($dirName, 0777, true);
         }
     }
     Vikont_Pulliver_Helper_Data::type("Downloading {$requestURL}/{$remoteFileName}...");
     $startedAt = time();
     if (!ftp_get($connection, $localFileName, $remoteFileName, FTP_BINARY)) {
         Vikont_Pulliver_Helper_Data::throwException(sprintf('Error downloading from FTP %s/%s to %s', $requestURL, $remoteFileName, $localFileName));
     }
     ftp_close($connection);
     $timeTaken = time() - $startedAt;
     Vikont_Pulliver_Helper_Data::inform(sprintf('Inventory successfully downloaded from %s/%s to %s, size=%dbytes, time=%ds', $requestURL, $remoteFileName, $localFileName, filesize($localFileName), $timeTaken));
     return $localFileName;
 }
Exemple #18
0
 /**
  * Salva o conteúdo do arquivo no servidor Oracle
  * Caso seja possível salvar o arquivo, será retornado
  * o filename completo de onde o arquivo será armazenado
  * 
  * @param Zend_Db $db
  * @return string
  */
 public function save($db = null)
 {
     if ($db == null) {
         $db = Zend_Registry::get('db.projta');
     }
     if ($this->_content instanceof ZendT_Type_Blob) {
         $sql = "\n                    declare\n                      v_blob BLOB;\n                    begin\n                       insert into tmp_blob(content) values (:content);\n                       select content into v_blob FROM tmp_blob;\n                       arquivo_pkg.write_to_disk(p_data => v_blob,\n                                                 p_file_name => :name,\n                                                 p_path_name => :path);\n                    end;                \n                ";
         @($conn = ftp_connect('192.168.1.251'));
         if (!$conn) {
             throw new ZendT_Exception(error_get_last());
         }
         @($result = ftp_login($conn, 'anonymous', 'anonymous'));
         if (!$result) {
             throw new ZendT_Exception(error_get_last());
         }
         $fileNameServer = 'pub/temp/' . $this->_name;
         @ftp_delete($conn, $fileNameServer);
         @($result = ftp_put($conn, $fileNameServer, $this->_fileName, FTP_BINARY));
         if (!$result) {
             throw new ZendT_Exception(error_get_last() . ". Name Server: {$fileNameServer} || Name Local: {$this->_fileName}");
         }
         @($result = ftp_close($conn));
     } else {
         $sql = "\n                    begin\n                    arquivo_pkg.write_to_disk(p_data => :content,\n                                              p_file_name => :name,\n                                              p_path_name => :path);\n                    end;                \n                ";
         $stmt = $db->prepare($sql);
         $stmt->bindValue(':content', $this->_content);
         $stmt->bindValue(':name', $this->_name);
         $stmt->bindValue(':path', $this->_path);
         $stmt->execute();
     }
     $filename = $this->_path . '/' . $this->_name;
     return $filename;
 }
 /**
  * @inheritdoc
  */
 public function run(&$cmdParams, &$params)
 {
     $controller = $this->controller;
     $res = false;
     $connectionId = !empty($cmdParams[0]) ? $cmdParams[0] : '';
     if (empty($connectionId)) {
         Log::throwException('sftpDisconnect: Please specify a valid connection id');
     }
     /** @noinspection PhpUndefinedMethodInspection (provided by the SftpConnectReqs Behavior) */
     $connParams = $controller->getConnectionParams($connectionId);
     $controller->stdout(" " . $connectionId . " ", $connParams['sftpLabelColor'], Console::FG_BLACK);
     $controller->stdout(' Closing connection ');
     if (!$controller->dryRun) {
         // the getConnection method is provided by the SftpConnectReqs Behavior
         /** @noinspection PhpUndefinedMethodInspection */
         /** @var $connection Net_SFTP|resource */
         $connection = $controller->getConnection($connectionId);
         switch ($connParams['sftpConnectionType']) {
             case SftpHelper::TYPE_SFTP:
                 $connection->disconnect();
                 break;
             case SftpHelper::TYPE_FTP:
                 ftp_close($connection);
                 break;
             default:
                 $controller->stdout("\n");
                 Log::throwException('Unsupported connection type: ' . $connParams['sftpConnectionType']);
                 break;
         }
     } else {
         $controller->stdout(' [dry run]', Console::FG_YELLOW);
     }
     $controller->stdout("\n");
     return $res;
 }
Exemple #20
0
 private function uploadPackageToFTP($account)
 {
     $connection = @ftp_connect($account['host']);
     if (!$connection) {
         cmsUser::addSessionMessage(LANG_CP_FTP_AUTH_FAILED, 'error');
         return false;
     }
     $session = @ftp_login($connection, $account['user'], $account['pass']);
     if (!$session) {
         cmsUser::addSessionMessage(LANG_CP_FTP_AUTH_FAILED, 'error');
         return false;
     }
     if ($account['is_pasv']) {
         ftp_pasv($connection, true);
     }
     if (!$this->checkDestination($connection, $account)) {
         return false;
     }
     $src_dir = $this->getPackageContentsDir();
     $dst_dir = '/' . trim($account['path'], '/');
     try {
         $this->uploadDirectoryToFTP($connection, $src_dir, $dst_dir);
     } catch (Exception $e) {
         ftp_close($connection);
         cmsUser::addSessionMessage($e->getMessage(), 'error');
         return false;
     }
     ftp_close($connection);
     $this->redirectToAction('install/finish');
     return true;
 }
Exemple #21
0
 /**
  * Fetch data file from Itella FTP server
  * @param $type Data file type (PCF = localities, BAF = street addresses, POM = zip code changes)
  * @returns Temp file name
  */
 public function fetchFile($type)
 {
     //Connect to FTP server
     $ftp = ftp_connect($this->host);
     if ($ftp === false) {
         throw new Exception("Could not connect to '{$this->host}'");
     }
     if (!ftp_login($ftp, $this->user, $this->password)) {
         throw new Exception("Login to '{$this->host}' as '{$this->user}' failed");
     }
     //Find filename to download
     ftp_pasv($ftp, true);
     $list = ftp_nlist($ftp, '.');
     $file = null;
     foreach ($list as $item) {
         $parts = explode('_', $item);
         if (isset($parts[0]) && strtoupper($parts[0]) == strtoupper($type)) {
             $file = $item;
         }
     }
     if ($file == null) {
         throw new Exception("'{$type}' file not found");
     }
     //Download requested data file
     $tmpFile = tempnam(sys_get_temp_dir(), 'FinZip_' . $type . '_') . '.zip';
     $this->tmpFiles[] = $tmpFile;
     $tmp = fopen($tmpFile, 'w');
     ftp_pasv($ftp, true);
     ftp_fget($ftp, $tmp, $file, FTP_BINARY);
     ftp_close($ftp);
     fclose($tmp);
     //Return the filename of the temporary file
     return $tmpFile;
 }
function syncFolderToFtp($host, $username, $password, $remote_backup, $backup_folder)
{
    $ftp = ftp_connect($host);
    // connect to the ftp server
    ftp_login($ftp, $username, $password);
    // login to the ftp server
    ftp_chdir($ftp, $remote_backup);
    // cd into the remote backup folder
    // copy files from folder to remote folder
    $files = glob($backup_folder . '*');
    $c = 0;
    $allc = count($files);
    foreach ($files as $file) {
        $c++;
        $file_name = basename($file);
        echo "\n {$c}/{$allc}: {$file_name}";
        $upload = ftp_nb_put($ftp, $file_name, $file, FTP_BINARY);
        // non-blocking put, uploads the local backup onto the remote server
        while ($upload == FTP_MOREDATA) {
            // Continue uploading...
            $upload = ftp_nb_continue($ftp);
        }
        if ($upload != FTP_FINISHED) {
            echo " ... ERROR";
        } else {
            echo " ... OK";
        }
    }
    ftp_close($ftp);
    // closes the connection
}
Exemple #23
0
	public function ftp_quit() {
		if ($this->conn_id) {
			@ftp_close($this->conn_id);
		}

		return;
	}
Exemple #24
0
function copyViaFtpRecursively($uploadLocation, $previewPath, $remoteDirectory, $ftpType)
{
    $errorMessage = '';
    $connectionId = getFtpConnection($uploadLocation['host'], $uploadLocation['username'], $uploadLocation['password'], $uploadLocation['port']);
    switch ($ftpType) {
        case 'active':
            ftp_pasv($connectionId, False);
            break;
        case 'passive':
            ftp_pasv($connectionId, True);
            break;
    }
    $baseDirectory = $uploadLocation['baseDirectory'];
    if (substr($baseDirectory, strlen($baseDirectory) - 1, 1) != '/') {
        $baseDirectory .= '/';
    }
    ftp_mkdir($connectionId, $baseDirectory);
    // No point showing an error message if the directory exists (most likely cause of error) because it will exist (at least) after the first time.
    $remoteBaseDirectory = $baseDirectory . $remoteDirectory;
    if (substr($remoteBaseDirectory, strlen($remoteBaseDirectory) - 1, 1) == '/') {
        $remoteBaseDirectory = substr($remoteBaseDirectory, 0, strlen($remoteBaseDirectory) - 1);
    }
    $remoteBaseDirectory .= '/';
    $errorMessage .= copyFileViaFtp($previewPath, $remoteBaseDirectory, $connectionId);
    ftp_close($connectionId);
    $errorHtml = '';
    if ($errorMessage) {
        $errorHtml = nl2br($errorMessage);
    }
    return $errorHtml;
}
Exemple #25
0
 public function __destruct()
 {
     if (!empty($this->stream)) {
         @ftp_close($this->stream);
     }
     $this->stream = null;
 }
Exemple #26
0
 public function getListing()
 {
     $dir = $this->directory;
     // Parse directory to parts
     $parsed_dir = trim($dir, '/');
     $this->parts = empty($parsed_dir) ? array() : explode('/', $parsed_dir);
     // Find the path to the parent directory
     if (!empty($parts)) {
         $copy_of_parts = $parts;
         array_pop($copy_of_parts);
         if (!empty($copy_of_parts)) {
             $this->parent_directory = '/' . implode('/', $copy_of_parts);
         } else {
             $this->parent_directory = '/';
         }
     } else {
         $this->parent_directory = '';
     }
     // Connect to the server
     if ($this->ssl) {
         $con = @ftp_ssl_connect($this->host, $this->port);
     } else {
         $con = @ftp_connect($this->host, $this->port);
     }
     if ($con === false) {
         $this->setError(JText::_('FTPBROWSER_ERROR_HOSTNAME'));
         return false;
     }
     // Login
     $result = @ftp_login($con, $this->username, $this->password);
     if ($result === false) {
         $this->setError(JText::_('FTPBROWSER_ERROR_USERPASS'));
         return false;
     }
     // Set the passive mode -- don't care if it fails, though!
     @ftp_pasv($con, $this->passive);
     // Try to chdir to the specified directory
     if (!empty($dir)) {
         $result = @ftp_chdir($con, $dir);
         if ($result === false) {
             $this->setError(JText::_('FTPBROWSER_ERROR_NOACCESS'));
             return false;
         }
     } else {
         $this->directory = @ftp_pwd($con);
         $parsed_dir = trim($this->directory, '/');
         $this->parts = empty($parsed_dir) ? array() : explode('/', $parsed_dir);
         $this->parent_directory = $this->directory;
     }
     // Get a raw directory listing (hoping it's a UNIX server!)
     $list = @ftp_rawlist($con, '.');
     ftp_close($con);
     if ($list === false) {
         $this->setError(JText::_('FTPBROWSER_ERROR_UNSUPPORTED'));
         return false;
     }
     // Parse the raw listing into an array
     $folders = $this->parse_rawlist($list);
     return $folders;
 }
Exemple #27
0
 public function close()
 {
     if ($this->connection) {
         ftp_close($this->connection);
     }
     return $this;
 }
Exemple #28
0
 public function close()
 {
     if (!empty($this->connectionId)) {
         ftp_close($this->connectionId);
     }
     return true;
 }
 /**
  * Uploads file to FTP server.
  * @return void
  */
 public function writeFile($local, $remote, callable $progress = NULL)
 {
     $size = max(filesize($local), 1);
     $retry = self::RETRIES;
     upload:
     $blocks = 0;
     do {
         if ($progress) {
             $progress(min($blocks * self::BLOCK_SIZE / $size, 100));
         }
         try {
             $ret = $blocks === 0 ? $this->ftp('nb_put', $remote, $local, FTP_BINARY) : $this->ftp('nb_continue');
         } catch (FtpException $e) {
             @ftp_close($this->connection);
             // intentionally @
             $this->connect();
             if (--$retry) {
                 goto upload;
             }
             throw new FtpException("Cannot upload file {$local}, number of retries exceeded. Error: {$e->getMessage()}");
         }
         $blocks++;
     } while ($ret === FTP_MOREDATA);
     if ($progress) {
         $progress(100);
     }
 }
Exemple #30
0
 public function close()
 {
     if (!$this->connect_id) {
         return false;
     }
     ftp_close($this->connect_id);
 }