ftp_connect example

/** * Connects filesystem. * * @since 2.5.0 * * @return bool True on success, false on failure. */
    public function connect() {
        if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) {
            $this->link = @ftp_ssl_connect( $this->options['hostname']$this->options['port'], FS_CONNECT_TIMEOUT );
        } else {
            $this->link = @ftp_connect( $this->options['hostname']$this->options['port'], FS_CONNECT_TIMEOUT );
        }

        if ( ! $this->link ) {
            $this->errors->add(
                'connect',
                sprintf(
                    /* translators: %s: hostname:port */
                    __( 'Failed to connect to FTP Server %s' ),
                    $this->options['hostname'] . ':' . $this->options['port']
                )
            );

            
namespace Drupal\Core\FileTransfer;

/** * Defines a file transfer class using the PHP FTP extension. */
class FTPExtension extends FTP implements ChmodInterface {

  /** * {@inheritdoc} */
  public function connect() {
    $this->connection = ftp_connect($this->hostname, $this->port);

    if (!$this->connection) {
      throw new FileTransferException("Cannot connect to FTP Server, check settings");
    }
    if (!ftp_login($this->connection, $this->username, $this->password)) {
      throw new FileTransferException("Cannot log in to FTP server. Check username and password");
    }
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.