Problem loading php ftp

I am trying to write a small php function that will upload files to an FTP server and I keep getting the same error, but I can not find any fix by going over the problem, I hope you guys can help me here ...

The error I get is: Warning: ftp_put () [function.ftp-put]: Unable to build data connection: there is no route to host.

The file was created on an FTP server, but it is zero.

Here is the code:

<?php
$file = "test.dat";

$ftp_server="ftp.server.com";
$ftp_user = "myname";
$ftp_pass = "mypass";
$destination_file = "test.dat";


$cid=ftp_connect($ftp_server);
if(!$cid) {
    exit("Could not connect to server: $ftp_server\n");
}

$login_result = ftp_login($cid, $ftp_user, $ftp_pass);
if (!$login_result) {
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user";
    exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user";
}

$upload = ftp_put($cid, $destination_file, $file, FTP_BINARY);
if (!$upload) {
    echo "Failed upload for $source_file to $ftp_server as $destination_file<br>";
    echo "FTP upload has failed!";
} else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
}

ftp_close($cid);
?>
+3
source share
1 answer

I forgot to put FTP in passive mode using:

ftp_pasv($cidtrue);
+7
source

Source: https://habr.com/ru/post/1748769/


All Articles