Hi i want to download csv files located on csv folder in root folder of one server to my server by using FTP connection. I added the below code . Its not working for me. FTP connection is working also all files are listed by using this command ftp_nlist.Can you please help me to download files form one folder of one server to another folder of server ?
$ftpHost = 'ftp.site.in';
$ftpUsername = 'username';
$ftpPassword = '******';
// open an FTP connection
$connId = ftp_connect($ftpHost) or die("Couldn't connect to $ftpHost");
// try to login
if(@ftp_login($connId, $ftpUsername, $ftpPassword)){
echo "Connected as $ftpUsername@$ftpHost";
}else{
echo "Couldn't connect as $ftpUsername";
}
$contents = ftp_nlist($connId, ".");
var_dump($contents);
// local & server file path
$localFilePath = 'csv';
$remoteFilePath = 'public_html/csvfiles/';
// try to download a file from server
if(ftp_get($connId, $localFilePath, $remoteFilePath, FTP_BINARY)){
echo "File transfer successful - $localFilePath";
}else{
echo "There was an error while downloading $localFilePath";
}