Skip to content

Commit

Permalink
fix-bug-and-remove-hardcoded-source-and-disconnect-before-reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
rlf authored and rlf committed Aug 29, 2019
1 parent ee51b79 commit 3bfade2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 10 additions & 7 deletions Command/TransferFileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$service->setMode($input->getOption('method'));

if ($service->getMode() === FileTransferService::MODE_GET) {
$files = $service->getRemoteFiles($targetserverid, '/PROD', $this->input->getOption('ignore', []));
$files = $service->getRemoteFiles($targetserverid, $sourcefile, $this->input->getOption('ignore', []));

if (is_array($files)) {
foreach ($files as $file) {
$service->transferFile(
Expand All @@ -67,12 +67,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$targetfile . $file);
}
}
}

if ($this->useDirectoryMode($sourcefile)) {
$this->transferDirectory($service, $targetserverid, $sourcefile, $targetfile);

} else {
$service->transferFile($targetserverid, $sourcefile, $targetfile);

if ($this->useDirectoryMode($sourcefile)) {
$this->transferDirectory($service, $targetserverid, $sourcefile, $targetfile);
} else {
$service->transferFile($targetserverid, $sourcefile, $targetfile);
}

}
}

Expand Down
5 changes: 4 additions & 1 deletion Service/FileTransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public function transferFile($serverid, $sourcefile, $targetfile)
throw new \RuntimeException("There is no mode selected please use -m or --method");
break;
}

$sftp->disconnect();

}

/**
Expand All @@ -111,7 +114,7 @@ private function loginInSftp(string $serverid)
$e = "Sftp login failed for user " . $username;
$this->logger->error($e);
throw new \RuntimeException($e);
}
}

return $sftp;
}
Expand Down

0 comments on commit 3bfade2

Please sign in to comment.