<?php
require_once 'config.php';
require_once 'functions.php';
// Ftp connection
$ftp_connection = ftp_connect($ftp_host) or die("Couldn't connect to $ftp_host");
ftp_login($ftp_connection, $ftp_user, $ftp_pass);
ftp_pasv($ftp_connection, true);
$local_dir = $_SERVER["DOCUMENT_ROOT"].'/all/clevertechie/ftptransfer/baseurl/';
$remote_server_dir = "/ftptransfer/here";
$files = clean_scandir($local_dir);
// pre_r($files);
echo $ftp_connection !== FALSE ? 'Connected' : "Couldn't connect";
echo "</br>";
for ($i=0; $i<count($files) ; $i++) {
$files_on_server = ftp_nlist($ftp_connection, $remote_server_dir);
// pre_r($files_on_server);die;
if (!in_array("$files[$i]",$files_on_server)) {
// upload images/files to the remote server
if(ftp_put($ftp_connection, "$remote_server_dir/$files[$i]", "$local_dir/$files[$i]",FTP_BINARY)){
echo "Succesfully uploaded $files[$i]";
echo "<br>";
}else {
echo "There was a problem while uploading a file";
echo "<br>";
}
}else {
echo "$files[$i] exists";
echo "<br>";
}
}
ftp_close($ftp_connection);
Above code works fine what it is intended for.
But this part →
$local_dir = $_SERVER["DOCUMENT_ROOT"].'/all/clevertechie/ftptransfer/baseurl/';
I want the local directory also to be fetched up through PHP and FTP. How should I accomplish this?
Both the source and destination are on the same server and on the same FTP connection.
I tried something like this →
$local_dir_url = "/ftptransfer/baseurl";
$local_dir = ftp_nlist($ftp_connection, $local_dir_url);
$remote_server_dir = "/ftptransfer/here";