How to configure FTP PHP - Help

4

When using WinSCP I perform the following steps: (dummy data)

hostname: bala.rimunivert.com.br username: zzzzzzz @ rjozzz000

after that he asks Gateway username: juliohenrique Gateway password: 1234566

and after that still appears: futher authentical required and then I put another password: blablabalaba

That is what I understand to access this server I need to authenticate myself in another first. The question that generates me is the following, how to implement this in my code?

//esse é um metodo de conexao da minha classe ftp
public function connect ($server, $ftpUser, $ftpPassword, $isPassive = false){

    // *** Set up basic connection
    $this->connectionId = ftp_connect($server);

    // *** Login with username and password
    $loginResult = ftp_login($this->connectionId, $ftpUser, $ftpPassword);

    // *** Sets passive mode on/off (default off)
    ftp_pasv($this->connectionId, $isPassive);

    // *** Check connection
    if ((!$this->connectionId) || (!$loginResult)) {
        $this->logMessage('FTP connection has failed!');
        $this->logMessage('Attempted to connect to ' . $server . ' for user ' . $ftpUser, true);
        return false;
    } else {
        $this->logMessage('Connected to ' . $server . ', for user ' . $ftpUser);
        $this->loginOk = true;
        return true;
    }
}

//minhas constantes definidas
define('FTP_HOST', 'bala.rimunivert.com.br');
define('FTP_USER', 'juliohenrique');
define('FTP_PASS', '1234566');

//como eu chamo esse metodo e algum arquivo
$ftpObj -> connect(FTP_HOST, FTP_USER, FTP_PASS);

This code would work if I did not have to authenticate to another server before accessing the server I want. I do not know if it was clear, but can anyone help me how should I make this connection?

How can I connect to send files on this type of network?

** Guys, someone gives me a light! by winscp I connect marking the SFTP option, what does this mean?

    
asked by anonymous 27.10.2017 / 15:52

1 answer

2

To access a server in the middle of the connection, use the phpseclib library. However, in this way you will not be able to use the native FTP functions of PHP, you will have to work as if you were on a command line (which in practice is that).

As I have presented above you will use the FTP client of the intermediate server for that connection.

Example of how to run phpseclib: link

    
27.10.2017 / 16:02