Reputation: 19
I want to FTP a certain file from my new server.
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);
Thanks alot, I searched alot on the internet but no way how to include it in a PHP script.
Upvotes: 1
Views: 980
Reputation: 4025
Have a look in the manual page for 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");
to
$port_number = 8821;
$ftp_connb = ftp_connect($ftp_serverb, $port_number) or die("Could not connect to $ftp_serverb");
Upvotes: 1