Jump to content

Need help with ftp_ssl_connect()


sKunKbad

Recommended Posts

I've been trying to connect to a CentOS server with ftp_ssl_connect, and I just get errors, even though I can successfully connect with FileZilla using FTPeS. These are the errors:

 

Warning: ftp_login() [function.ftp-login]: SSL/TLS handshake failed in C:\xampp\htdocs\script-library\connectivity\connectivity.php on line 72

Warning: ftp_login() [function.ftp-login]: Proceed with negotiation. in C:\xampp\htdocs\script-library\connectivity\connectivity.php on line 72

 

The server has vsftpd for ftp. It is configured for SSL, and again it works with FileZilla FTP client, so I don't know why it doesn't work with my PHP. Other than the above error messages, I don't really know how to debug or get more info.

 

$ftp_server = '123.123.123.123';
$ftp_user_name = 'username';
$ftp_user_pass = 'xxxxxxxxx';
$file = 'test.txt';
$remote_file = 'test.txt';
$remote_directory = '/home/username';

$ftp_output = '';

// Test if connection is HTTP or HTTPS
if ( 
isset( $_POST['do_ftp'] )
&& $_POST['do_ftp'] == '1'
)
{
if(
	isset( $_SERVER['HTTPS'] ) 
	&& $_SERVER['HTTPS'] == 'on' 
	&& function_exists('ftp_ssl_connect')
)
{
	// Set up secure ftp connection
	$conn_id = @ftp_ssl_connect( $ftp_server );
}
else
{
	// Set up standard ftp connection
	$conn_id = @ftp_connect( $ftp_server );
}
}

// Check if connection was made
if( is_resource( $conn_id ) )
{
$ftp_output .= '<span class="good">FTP CONNECTION SUCCESSFUL</span><br />';

// Login with username and password
if( $login_result = ftp_login( $conn_id, $ftp_user_name, $ftp_user_pass ) )
{
	$ftp_output .= '<span class="good">FTP LOGIN SUCCESSFUL</span><br />';

	// Turn passive mode on
	ftp_pasv( $conn_id, TRUE );

	// CD to the appropriate directory
	ftp_chdir( $conn_id, $remote_directory );

	// Upload a file
	if ( ftp_put( $conn_id, $remote_file, $file, FTP_ASCII ) )
	{
		$ftp_output .= '<span class="good">FTP UPLOAD OF ' . $file . ' SUCCESSFUL</span><br />';
	} 
	else 
	{
		$ftp_output .= '<span class="bad">FTP UPLOAD OF ' . $file . ' FAILED</span><br />';
	}
}
else
{
	$ftp_output .= '<span class="bad">FTP LOGIN FAILED</span><br />';
}

// Close the FTP connection
ftp_close( $conn_id );
}
else if( isset( $conn_id ) )
{
$ftp_output .= '<span class="bad">FTP CONNECTION FAILED</span><br />';
}

 

Output from FTP:

FTP CONNECTION SUCCESSFUL

FTP LOGIN FAILED

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.