How to set up PHP FTP - Help

Asked

Viewed 254 times

4

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

hostname: bala.rimunivert.com.br username: zzzzzzz@rjozzz 000

after that he asks Gateway username: juliohenrique Password gateway: 1234566

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

That is, as far as I understand to access this server, I need to authenticate myself to another one 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', '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 didn’t have to authenticate myself on another server before accessing the server I want. I don’t know if it’s clear, but someone can help me make this connection?

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

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

1 answer

2


To access a server in the middle of the connection use the library phpseclib. However, 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 just that).

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

Example of how to run phpseclib: https://stackoverflow.com/questions/6270419/how-to-execute-ssh-commands-via-php

  • Is there any way to do this using only PHP native functions?

  • I don’t know otherwise, the server that is running your PHP code has to have access to the FTP server either directly or with a proxy, but I want to track if any ninja knows more about it..

  • I can’t access that lib proxy here blocks haha, I’ll have to see at home.

  • Right, take advantage and make a drawing of the architecture of this network, so we can help more!!

  • from what I understand here is just a proxy that needs to be authenticated before accessing the server ftp. You think with phpseclib I can do this?

  • @Juliohenrique97 is why I asked for the architecture, I understood that there is a server in the middle that has access to the server with FTP. This is very common in corporate networks, but if it is a proxy you can use native PHP functions

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.