Riffaz Starr
Riffaz Starr

Reputation: 611

How to copying FTP files to an specific folders.?

I have .txt file named files.txt which contains a list of file names.

files.txt

index.php.bk-2013-12-02
index.php.bk-2013-12-07
index.php.bk-2013-12-10
index.php.bk-2013-12-20
index.php.bk-2013-12-26
function.php.bk-2013-12-20
function.php.bk-2013-12-23
contact.php.bk-2013-12-23
contact.php.bk-2013-12-30

I want to copy these files to the directory backup NO need to recursive.. just wanna copy as it is.

My httpdocs folder looks like this

after I execute the script file, the above mentioned .php.bk files must be copied in to the folder backup

How can I do that pals? any help will be very much appreciated.

Thanks.

Upvotes: 0

Views: 150

Answers (1)

Matthias Dunkel
Matthias Dunkel

Reputation: 305

Read the file line by line and then just copy the file to your 'backup' folder:

$files = "files.txt";
$lines = file($files);
foreach($lines as $file)
{
    $file = trim($file);
    copy($dir . '/' . $file, $dir . '/backup/' . $file);
}

But that has nothing to do with FTP, right?

Also, if your files alway habe .bak- in their name, this may be easier:

foreach (glob("*.bk-*") as $filename) {
    copy($filename, 'backup/' . $filename);
}

Upvotes: 1

Related Questions