ftp\SIG_Upload::_init_transfers PHP Method

_init_transfers() protected method

Processes any files awaiting to upload and attempts to begin the upload transfer.
protected _init_transfers ( ) : void
return void
    protected function _init_transfers()
    {
        foreach ($this->_files as $_k => $_file) {
            if (!$_file instanceof File) {
                continue;
            }
            if ($this->_options['secure']) {
                $connection = ftp_ssl_connect($this->_options['hostname'], $this->_options['port'], $this->_options['timeout']);
            } else {
                $connection = ftp_connect($this->_options['hostname'], $this->_options['port'], $this->_options['timeout']);
            }
            if (false === $connection) {
                break;
            }
            $login = ftp_login($connection, $this->_options['username'], $this->_options['password']);
            if ($login === false) {
                $this->_sig_failure->set_upload($_file);
                xp_emit($this->_sig_failure, new SIG_Failure($_file));
                ftp_close($connection);
                break;
            }
            if (!file_exists($_file->get_full_path())) {
                xp_emit($this->_sig_failure, new SIG_Failure($_file));
            } else {
                $transfer = ftp_nb_put($connection, $_file->get_name(), $_file->get_full_path(), $_file->get_transfer_mode());
                if ($transfer === FTP_MOREDATA) {
                    $this->_uploading[] = [$connection, $_file];
                } else {
                    if ($transfer == FTP_FINISHED) {
                        $this->_sig_complete->set_upload($_file);
                        xp_emit($this->_sig_complete);
                        // Close the FTP connection to that file
                        ftp_close($connection);
                        $this->_uploaded[] = $_file;
                    } else {
                        $this->_sig_failure->set_upload($_file);
                        xp_emit($this->_sig_failure);
                        // Close the FTP connection to that file
                        ftp_close($connection);
                    }
                }
            }
            unset($this->_files[$_k]);
        }
    }