Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. <?php
  2. $host = 'example.com';
  3. $password = 'pass';
  4. $username = 'username';
  5.  
  6. try {
  7. $result = checkFtp($host, $username, $password);
  8. } catch(Exception $e) {
  9. $result = $e->getMessage();
  10. }
  11.  
  12. if($result) {
  13. print 'ok';
  14. } else {
  15. print 'fail';
  16. }
  17.  
  18. function checkFtp($host, $username, $password, $port = 21, $timeout = 10) {
  19. $con = ftp_connect($host, $port, $timeout);
  20. if (false === $con) {
  21. throw new Exception('Unable to connect to FTP Server.');
  22. }
  23. $loggedIn = ftp_login($con, $username, $password);
  24. ftp_close($con);
  25. if (true === $loggedIn) {
  26. return true;
  27. } else {
  28. throw new Exception('Unable to log in.');
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement