Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'example.com';
- $password = 'pass';
- $username = 'username';
- try {
- $result = checkFtp($host, $username, $password);
- } catch(Exception $e) {
- $result = $e->getMessage();
- }
- if($result) {
- print 'ok';
- } else {
- print 'fail';
- }
- function checkFtp($host, $username, $password, $port = 21, $timeout = 10) {
- $con = ftp_connect($host, $port, $timeout);
- if (false === $con) {
- throw new Exception('Unable to connect to FTP Server.');
- }
- $loggedIn = ftp_login($con, $username, $password);
- ftp_close($con);
- if (true === $loggedIn) {
- return true;
- } else {
- throw new Exception('Unable to log in.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement