Skip to content

Commit e71d8c5

Browse files
author
Igor Chepurnoy
authored
Merge pull request #5 from cpuche/master
Add getAll() method
2 parents 85d31c1 + db520ee commit e71d8c5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

FtpClient.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,35 @@ public function connect($host, $ssl = false, $port = 21, $timeout = 90)
145145
return $this;
146146
}
147147

148+
/**
149+
* Download files
150+
*
151+
* @param string $source_directory
152+
* @param string $target_directory
153+
* @param int $mode
154+
*
155+
* @return FtpClient
156+
*/
157+
public function getAll($source_directory, $target_directory, $mode = FTP_BINARY)
158+
{
159+
$d = $this->scanDir($source_directory);
160+
161+
// do this for each file in the directory
162+
foreach($d as $file) {
163+
$new_source_directory = $source_directory . '/' . $file['name'];
164+
$new_target_directory = $target_directory . '/' . $file['name'];
165+
if($file['type'] == 'directory'){
166+
if(!is_dir($new_target_directory)){
167+
mkdir($new_target_directory);
168+
}
169+
$this->getAll($new_source_directory, $new_target_directory);
170+
} else {
171+
$this->get($new_target_directory, $new_source_directory, $mode);
172+
}
173+
}
174+
return $this;
175+
}
176+
148177
/**
149178
* Get the connection with the server
150179
*

0 commit comments

Comments
 (0)