我试图为我的服务器的cPanel帐户使用自动备份脚本 我已经使用FileZilla Server在一台本地计算机上安装了FTP服务器。 我可以使用FileZilla客户端,Plesk服务器和lftp ...成功连接和传输文件 服务器仅接受加密连接,并启用被动模式。
由于某些未知原因,当尝试使用PHP连接和放置文件时,响应为:
警告:ftp_put():php_connect_nonb()失败:现在进行操作 进展(115)在 第326行/home/xxxxxxx/public_html/lab/test/perform_mysql_bk.php
对此错误的任何想法?
对于我使用的连接:
$fSuccess = false;
$sServerAddress = $this->m_aConfig['FTP_SERVER_ADDRESS'];
$iServerPort = (int)( $this->m_aConfig['FTP_SERVER_PORT'] );
// set up FTP connection
if ( ($this->m_aConfig['FTP_USE_SSL'] == 'YES') ) {
if ( function_exists('ftp_ssl_connect') ) {
$this->m_oFtpConnection = ftp_ssl_connect( $sServerAddress, $iServerPort );
if ( !$this->m_oFtpConnection ) {
$this->writeLog( "Attempt to connect to ".$sServerAddress.":".$iServerPort." with SSL+FTP failed. Will fallback to normal FTP." );
}
else {
$this->writeLog( "Attempt to connect to ".$sServerAddress.":".$iServerPort." with SSL+FTP Succeeded. Now logging in ..." );
}
}
else {
$this->writeLog( "This server doesn't support FTPS (FTP with SSL). Will fallback to normal FTP." );
}
}
//Fallback
if ( !$this->m_oFtpConnection ) {
$this->m_oFtpConnection = ftp_connect( $sServerAddress, $iServerPort );
}
// login after a successful connection
if ( $this->m_oFtpConnection ) {
$fLoginResult = ftp_login( $this->m_oFtpConnection, $this->m_aConfig['FTP_USERNAME'], $this->m_aConfig['FTP_PASSWORD'] );
//echo $fLoginResult;
}
else {
$this->writeLog( "Attempt to connect to ".$sServerAddress.":".$iServerPort." failed." );
}
// check connection
if ( (!$this->m_oFtpConnection) || (!$fLoginResult) ) {
$this->writeLog( "FTP connection has failed!" );
} else {
$this->writeLog( "FTP connection was successful with ".$sServerAddress.":".$iServerPort );
$fSuccess = true;
}
// Set to Passive connection if login was successful and this setting was set.
if ( $fSuccess && ($this->m_aConfig['FTP_USE_PASSIVE'] == 'YES') ) {
if ( ftp_pasv( $this->m_oFtpConnection, true ) ) {
$this->writeLog( "FTP connection was set to PASSIVE mode." );
}
else {
$this->writeLog( "Attempted to set FTP connection to PASSIVE mode but failed. Going to continue with copy anyway. If the script fails, review this as a possible source." );
}
}
响应成功:(我用xx值替换了我的IP)
尝试使用SSL + FTP成功连接到xx.xx.xx.xx:21。现在 登录...
使用xx.xx.xx.xx成功进行FTP连接:21
FTP连接设置为PASSIVE模式。
但是当系统遇到这个时:
$fSuccess = false;
$sDestinationFile = $this->m_aConfig['FTP_PATH_TO_COPY'] . $insDbFileName;
// upload the file
$fUpload = ftp_put( $this->m_oFtpConnection, $sDestinationFile, $insDbFileName, FTP_BINARY );
// check upload status
if (!$fUpload) {
$this->writeLog( "FTP upload has failed! Check the log file for errors. Try changing PASSIVE and SSL options in the config." );
return false;
} else {
$this->writeLog( "Uploaded $insDbFileName to ".$this->m_aConfig['FTP_SERVER_ADDRESS']." as $sDestinationFile" );
$fSuccess = true;
}
return $fSuccess;
响应是错误
警告:ftp_put():php_connect_nonb()失败:现在进行操作 进展(115)在 第326行/home/xxxxxxx/public_html/lab/test/perform_mysql_bk.php
我看过很多页面说这个错误是由于FTP服务器返回一个内部IP地址而不是公共,但我已经测试过其他程序并且所有运行正常,FTP服务器在PASV时发送公共IP命令执行。
有什么想法吗?
答案 0 :(得分:1)
PHP代码和curl的类似行为表明防火墙阻止了数据连接。
由于未加密的连接有效,防火墙很可能是智能的"通过监控FTP控制连接并自动转发控制连接中的数据连接端口。但这对加密会话不起作用,因为防火墙无法监控它们。
另请参阅"智能防火墙/ NAT"我的guide about network set up for FTP部分。
如果您需要允许加密连接,则需要与服务器管理员联系。
答案 1 :(得分:0)
我有同样的问题,已通过将ftp服务器ip添加到防火墙允许ip列表中来解决
答案 2 :(得分:0)
ftp_set_option($ftpconn, FTP_USEPASVADDRESS, false);
此代码行在设置连接的无源性之前
ftp_pasv($ftpconn, true);
救了我的命。