FTP连接失败
问题描述:
FTP连接失败。请帮帮我。FTP连接失败
$ftpServer = "xxxx.xxx"; //I have put the IP address
$username = "api";
$password = "api123";
$connId = @ftp_connect($ftpServer); - not Connecting
使用FileZilla中与上述凭证传递端口为22的时候不working.But,它的工作在FileZilla中。
但是通过 $ connId = @ftp_connect($ ftpServer,22); - 未连接
我已经在服务器 搭配chmod 777 -R目录名资源文件夹 做这些增加的API用户阿帕奇组 /usr/sbin目录/ usermod命令-a -G阿帕奇API
答
你有没有试过这个脚本?
<?php
function getFtpConnection($uri)
{
// Split FTP URI into:
// $match[0] = ftp://username:[email protected]/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;
}
?>
希望这可以帮助你
摆脱'@'的。这抑制了错误信息! – delboy1978uk
只是一个快速提醒,我可以看到你的IP –
可能重复[如何与PHP SFTP?](https://stackoverflow.com/questions/4689540/how-to-sftp-with-php)(SSH与FTP无关,同样的,端口22是用于SSH/SFTP,而不是用于FTP =>您需要使用SFTP而不是FTP。) –