如何在PHP FTP中包含端口 [英] How to include a port in PHP FTP
本文介绍了如何在PHP FTP中包含端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从新服务器上通过FTP传输特定文件.
I want to FTP a certain file from my new server.
新服务器不使用默认端口21
,而是使用8821
,我的FTP出现了一些问题.所以我认为这可能是问题所在.
The new server does not use the default port 21
but uses 8821
and I have some problems with my FTP. So I thought this could maybe be the problem.
如何在当前脚本中包含端口,或者甚至不需要?
How to include a port in my current script, or isn't it even needed?
$logfile = $_GET['logfile'];
$currentlog = "$logfile";
$ftp_usernameb = 'username';
$ftp_userpassb = 'pass';
$ftp_serverb = "host";
$ftp_connb = ftp_connect($ftp_serverb) or die("Could not connect to $ftp_serverb");
$loginb = ftp_login($ftp_connb, $ftp_usernameb, $ftp_userpassb);
$local_fileb = "$currentlog";
$server_fileb = "/188.40.46.30:7800/".$currentlog."";
// download server file
if (ftp_get($ftp_connb, $local_fileb, $server_fileb, FTP_ASCII))
{
//Downloaded continue with script
?>
<font color="green"><b>The logs have been updated succesfully!</b></font>
<meta http-equiv="refresh" content="0; url=?action=done&logfile=<?php echo $_GET['logfile']; ?>&search=<?php echo $_GET['search']; ?>" />
<?php
}
else
{
?>
<font color="red"><b>Couldn't update logs, contact Jesse!</b></font>
<meta http-equiv="refresh" content="0; url=?action=failed&logfile=<?php echo $_GET['logfile']; ?>&search=<?php echo $_GET['search']; ?>" />
<?php
exit;
}
// close connection
ftp_close($ftp_connb);
非常感谢,我在互联网上进行了大量搜索,但没有办法将其包含在PHP脚本中.
Thanks alot, I searched alot on the internet but no way how to include it in a PHP script.
推荐答案
在手册页中查看 ftp_connect :
resource ftp_connect ( string $host [, int $port = 21 [, int $timeout = 90 ]] )
现在您要做的就是通过更改
Now all you have to do is add the second parameter in your code by changing
$ftp_connb = ftp_connect($ftp_serverb) or die("Could not connect to $ftp_serverb");
到
$port_number = 8821;
$ftp_connb = ftp_connect($ftp_serverb, $port_number) or die("Could not connect to $ftp_serverb");
这篇关于如何在PHP FTP中包含端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文