0

FTP connection failed. Please help me.

 $ftpServer = "xxxx.xxx"; //I have put the IP address
 $username = "api";
 $password = "api123";

 $connId = @ftp_connect($ftpServer);  - not Connecting

using FileZilla with above credential not working.But when passing port as 22, It's working in FileZilla.

But through $connId = @ftp_connect($ftpServer, 22); -- Not Connecting

I have done these in server chmod 777 -R directoryName Resources Folder adding api user to apache group /usr/sbin/usermod -a -G apache api

Keerthana
  • 27
  • 4

1 Answers1

0

Did you tried this script?

<?php 
function getFtpConnection($uri) 
{ 
// Split FTP URI into: 
// $match[0] = ftp://username:password@sld.domain.tld/path1/path2/ 
// $match[1] = ftp:// 
// $match[2] = username 
// $match[3] = password 
// $match[4] = sld.domain.tld 
// $match[5] = /path1/path2/ 
preg_match("/ftp:\/\/(.*?):(.*?)@(.*?)(\/.*)/i", $uri, $match); 

// Set up a connection 
$conn = ftp_connect($match[1] . $match[4] . $match[5]); 

// Login 
if (ftp_login($conn, $match[2], $match[3])) 
{ 
    // Change the dir 
    ftp_chdir($conn, $match[5]); 

    // Return the resource 
    return $conn; 
} 

// Or retun null 
return null; 
} 
?>

hope this can help you

philip888
  • 27
  • 1
  • 6
  • 1
    How is that going to help when in first stance ftp_connect already is the issue? – rndus2r Sep 27 '17 at 11:54
  • The `vsftpd` service got off in the server, I hope this happened after the server maintenance. once stared that ftp_connect is working. But when is being off. through Filezila by passing the port 22. I was able to connect. How that is possible? – Keerthana Oct 02 '17 at 11:47