Reputation: 561
He Everyone,
I am trying to get files from FTP 1 to FTP 2 using FTP functions in PHP. I am able to locate the files and get the list too from FTP 2. But I do not know how can I copy those files to FTP 1. This is how far I have reached.
$ftp_server = "********";
$ftp_user_name = "******";
$ftp_user_pass = "******";
$ftp_dir = "*********";
$mode = "list_xml_files";
$file_list = ftp_list_xml_files ($ftp_server,$ftp_user_name,$ftp_user_pass,$ftp_dir,$mode,$file);
print_r($file_list);
die;
Upto this point it is working perfectly and here is the output of $file_list
Array ( [0] => orders01-04-2014.xml [1] => orders02-04-2014.xml )
Now I want to place these two xmls on FTP 1... Any idea how can I copy both of them an d put them on my FTP 1?
Thanks
Upvotes: 0
Views: 546
Reputation: 21
You could also use file_put_contents and fopen to do it.
<?php
file_put_contents($save_location, fopen($filename, 'r'));
?>
And you could use that to download all the files you specified in the array using foreach:
<?php
foreach($file_list as $filename)
file_put_contents($save_location, fopen($filename, 'r'));
?>
And you would replace $save_location with a location on your server where you wish to download the file. Example:
$location = "{$_SERVER['DOCUMENT_ROOT']}/files/downloads";
Hope it helped.
Upvotes: 1