How to set up PHP FTP – Help


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

hostname: username: zzzzzzz@rjozzz000

after that it asks for Gateway username: juliohenrique Gateway password: 1234566

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

that is, from what I understand to access this server I need to authenticate myself in another first. The doubt 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', '');
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 didn't have to authenticate to another server before accessing the server I want. I don't know if it was clear, but can someone help me with how I should make this connection?

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

**Guys, someone give me a light! through winscp I connect by checking the SFTP option, what does that mean?


To access a server across the connection use the phpseclib library. However, this way you won't be able to use PHP's native FTP functions, you'll have to work as if you were on a command line (which in practice is exactly that).

As presented above you will use the FTP client of the intermediary server of this connection.

Example of how to run phpseclib:

Scroll to Top