I’ve run this script before on another server without problems but getting the following error in my logs:
AH01071: Got error ‘PHP message: PHP Warning: ftp_get(): PORT command
is disabled in /path/to/file
The script results in “There was a problem”….
The code should connect to an external FTP server to download a specific file and place it locally on my server. The connection is made and the login is successful. It is this line that causes the problem:
<code>if (ftp_get($conn_id, $local_file, $server_file)) {
</code>
<code>if (ftp_get($conn_id, $local_file, $server_file)) {
</code>
if (ftp_get($conn_id, $local_file, $server_file)) {
Full Code:
<code><?php
$server_file = "testfile.xml.gz";
$local_file = 'tfs.xml.gz';
$ftp_server="aftp.xxx.com";
$ftp_user_name="xxx_xxxx";
$ftp_user_pass="xxxxx";
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file)) {
echo "Successfully written to $local_filen";
}
else {
echo "There was a problemn";
}
// close the connection
ftp_close($conn_id);
?>
</code>
<code><?php
$server_file = "testfile.xml.gz";
$local_file = 'tfs.xml.gz';
$ftp_server="aftp.xxx.com";
$ftp_user_name="xxx_xxxx";
$ftp_user_pass="xxxxx";
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file)) {
echo "Successfully written to $local_filen";
}
else {
echo "There was a problemn";
}
// close the connection
ftp_close($conn_id);
?>
</code>
<?php
$server_file = "testfile.xml.gz";
$local_file = 'tfs.xml.gz';
$ftp_server="aftp.xxx.com";
$ftp_user_name="xxx_xxxx";
$ftp_user_pass="xxxxx";
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file)) {
echo "Successfully written to $local_filen";
}
else {
echo "There was a problemn";
}
// close the connection
ftp_close($conn_id);
?>
- I have disabled my firewall temporarily but it made no difference.
- The local file has 777 permissions.
- The remote server’s owner’s only
stipulation is to use Binary transfer mode. - I can connect fine via Filezila and download the file.
- My server is Plesk Obsidian if that is relevant.
Any ideas gratefully received…