Jump to content

How on earth do we use the Ftp field in 4.2?


HeadStand

Recommended Posts

Posted

I had this code in 4.1 that worked perfectly:

$form->add( new \IPS\Helpers\Form\Ftp( 'directory_ftp', $this->ftp, true, array(
            'validate' => false
        ), function( $val ){
            if( empty( $val ) )
            {
                $val = \IPS\Request::i()->directory_ftp;
            }

            $conn_id = ftp_connect( $val['server'], $val['port'] );
            $login_result = ftp_login( $conn_id, $val['un'], $val['pw'] );
            if( !$conn_id || !$login_result )
            {
                throw new \InvalidArgumentException( 'FTP Connection Failed' );
            }

            ftp_pasv( $conn_id, true );
            if( !ftp_chdir( $conn_id, $val['path'] ) )
            {
                throw new \InvalidArgumentException( 'Could not change directory' );
            }

            ftp_close( $conn_id );
        } ) );

This is completely broken in 4.2. I needed to use a custom validation function because the standard FTP connection didn't work correctly for this particular server. All good. However, now I see that the value passed in to the custom validation function has pw set to '*******'. I am playing around with \IPS\Text\Encrypt and I cannot get the password out if you held a gun to my head.

Anyone have any suggestions?

Posted
$ftpData = $this->ftp;
	
$form->add( new \IPS\Helpers\Form\Ftp( 'directory_ftp', $this->ftp, true, array(
            'validate' => false
        ), function( $val ) use($ftpData) {
            if( empty( $val ) )
            {
                $val = \IPS\Request::i()->directory_ftp;
            }

            if ($val['pw'] === '********')
            {
                $val['pw'] = $ftpData['pw'];
            }

            $conn_id = ftp_connect( $val['server'], $val['port'] );
            $login_result = ftp_login( $conn_id, $val['un'], $val['pw'] );
            if( !$conn_id || !$login_result )
            {
                throw new \InvalidArgumentException( 'FTP Connection Failed' );
            }

            ftp_pasv( $conn_id, true );
            if( !ftp_chdir( $conn_id, $val['path'] ) )
            {
                throw new \InvalidArgumentException( 'Could not change directory' );
            }

            ftp_close( $conn_id );
        } ) );

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...