Skip to content

Downloading multiple Files #34

Description

@PenneiU

Source:

$this->Ftp = new Ftp();
$this->Ftp->useDbConfig = 'ftpServer';
$this->Ftp->connect();
try {
$files = $this->Ftp->find('all', array('conditions' => array('path' => $this->rootFileDirectoryFTP)));
} catch (Exception $e) {
debug($e->getMessage());
}
foreach ($files as $value) {
if ($value['Ftp']['is_dir'] == 0 && $value['Ftp']['is_link'] == 0) {
$remotefile = $value['Ftp']['path'] . $value['Ftp']['filename'];
$localfile = $this->rootFileDirectoryPC . $value['Ftp']['filename'];
$this->out($remotefile);
$this->out($localfile);
try {
if ($this->Ftp->save(array(
'local' => $localfile,
'remote' => $remotefile,
'direction' => 'down',
))) {
$this->out('Success!');
}
} catch (Exception $e) {
$this->out($e->getMessage());
}
}
}

Result:

/var/www/omarbeit/CONTRIBUTING.md
C:\testroot\CONTRIBUTING.md
Failed to download
/var/www/omarbeit/README.md
C:\testroot\README.md
Could not change directory
/var/www/build.properties
C:\testroot\build.properties
Failed to download
/var/www/build.xml
C:\testroot\build.xml
Could not change directory
/var/www/composer.json
C:\testroot\composer.json
Failed to download

System:

PC: Windows 7
FTP: Debian Wheezy

Problem:

If I try to download multiple files from the FTP which I have found by FTP->find(), I am getting once the error "Failed to download" and then once the error "Could not change directory". If I use for example this
$remotefile = $value['Ftp']['path'] . 'composer.json';
$localfile = $this->rootFileDirectoryPC . $value['Ftp']['filename'];
$this->out($remotefile);
$this->out($localfile);
try {
if ($this->Ftp->save(array(
'local' => $localfile,
'remote' => $remotefile,
'direction' => 'down',
))) {
$this->out('Success!');
}
} catch (Exception $e) {
$this->out($e->getMessage());
}

It success

/var/www/composer.json
C:\testroot\composer.json
Success!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions