note 109124 added to function.ftp-login

From: Date: Thu, 21 Jun 2012 22:21:30 +0000
Subject: note 109124 added to function.ftp-login
Groups: php.notes 
Request: Send a blank email to php-notes+get-188742@lists.php.net to get a copy of this message
<?php # This function fix problems with ftp login validation function connect_send_ftp($ftp_server, $ftp_user_name, $ftp_user_pass, $remote_name, $local_name) { // valid host connection if (!ftp_connect($ftp_server)) return false; $conn_id = ftp_connect($ftp_server); // valid ftp login params, fast check if(empty($ftp_user_name) or empty($ftp_user_pass)) return false; // using curl to valid login, fast check $curl = curl_init(); curl_setopt($curl, CURLOPT_URL,'ftp://'.preg_replace('/^ftp[:]\/\//i','',$ftp_server)); curl_setopt($curl, CURLOPT_FTPLISTONLY, 1); curl_setopt($curl, CURLOPT_USERPWD, $ftp_user_name.":".$ftp_user_pass); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $valid_login = curl_exec ($curl); // valid ftp login, primary if(!$valid_login) return false; // valid ftp login, secondary if(!ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)) return false; // passive result $passive_result = ftp_pasv($conn_id, true); // save file send erros $error = ftp_put($conn_id, $remote_name, $local_name, FTP_ASCII); // close connection ftp_close($conn_id); // return success or send erros return $error; } // set params $ftp_server = "ftp.example.com" $ftp_user_name = "user"; $ftp_user_pass = "password"; $remote_name = "my_remote_file_dir"; $local_name = "my_local_file_dir"; // call the function $conn = connect_send_ftp($ftp_server, $ftp_user_name, $ftp_user_pass, $remote_name, $local_name); // valid response if(!$conn) die("FTP login failed..") // if not erros, success echo "FTP login and file sended sucessfull!" ?> ---- Server IP: 187.73.33.52 Probable Submitter: 187.16.52.18 ---- Manual Page -- http://www.php.net/manual/en/function.ftp-login.php Edit -- https://master.php.net/note/edit/109124 Del: integrated -- https://master.php.net/note/delete/109124/integrated Del: useless -- https://master.php.net/note/delete/109124/useless Del: bad code -- https://master.php.net/note/delete/109124/bad+code Del: spam -- https://master.php.net/note/delete/109124/spam Del: non-english -- https://master.php.net/note/delete/109124/non-english Del: in docs -- https://master.php.net/note/delete/109124/in+docs Del: other reasons-- https://master.php.net/note/delete/109124 Reject -- https://master.php.net/note/reject/109124 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188742) next »