## Getting Started
### Minimal Setup
1. **Installation**: Add the bundle via Composer:
```bash
composer require clickandmortar/remote-bundle
config/bundles.php:
ClickAndMortar\RemoteBundle\ClickAndMortarRemoteBundle::class => ['all' => true],
php bin/console candm:remote:get ftp user@example.com /remote/path/file.txt ./local/directory
(Replace ftp with sftp, scp, or other supported types from the bundle.)config/packages/clickandmortar_remote.yaml (if auto-generated) or the bundle’s docs for available transfer types (e.g., ftp, sftp, scp)..env or a secure config file. Example:
REMOTE_SERVER=ftp.example.com
REMOTE_USER=admin
REMOTE_PASSWORD=secure123
schedule:run or a cron job:
* * * * * cd /path/to/project && php artisan schedule:run >> /dev/null 2>&1
php bin/console candm:remote:get ftp {REMOTE_USER} /backups/*.sql ./storage/backups --schedule
Storage facade to interact with downloaded files:
use Illuminate\Support\Facades\Storage;
// After download, process the file
$filePath = './local/directory/received_file.csv';
$contents = Storage::disk('local')->get($filePath);
// Parse/process $contents...
User is created).EventServiceProvider:
public function boot()
{
User::created(function ($user) {
$this->uploadAvatar($user->avatar_path);
});
}
protected function uploadAvatar($localPath)
{
$command = "candm:remote:put sftp {$this->remoteUser} {$localPath} /remote/avatars/{$user->id}.jpg";
exec($command);
}
collect() to iterate over files:
$remoteFiles = ['file1.txt', 'file2.txt'];
collect($remoteFiles)->each(function ($file) {
Artisan::call('candm:remote:get', [
'type' => 'sftp',
'user' => 'admin',
'distantFilePaths' => "/remote/{$file}",
'localDirectory' => './downloads',
]);
});
try-catch to log failures:
try {
Artisan::call('candm:remote:get', [...]);
} catch (\Exception $e) {
Log::error("Remote transfer failed: {$e->getMessage()}");
}
config/packages/clickandmortar_remote.yaml:
click_and_mortar_remote:
default_timeout: 30 # Override timeout in seconds
retries: 3 # Add retry logic for failed transfers
RemoteService in PHPUnit:
$this->partialMock(ClickAndMortar\RemoteBundle\Service\RemoteService::class, ['download']);
Protocol Limitations:
scp lacks directory listing).src/Service/RemoteService.php). Fall back to sftp for complex operations.Permission Errors:
php bin/console candm:remote:get -v ftp user@example.com /file.txt ./local
File Path Handling:
$localPath = realpath('./relative/path/file.txt');
Command Line Escaping:
-- to separate options:
php bin/console candm:remote:get ftp user@example.com "/path/with spaces/file.txt" "./local/dir"
APP_DEBUG=true) and check storage/logs/laravel.log.touch test.txt && php bin/console candm:remote:put ftp user@example.com test.txt /remote/test.txt
php bin/console candm:remote:get -t 60 ftp user@example.com /file.txt ./local
Custom Protocols:
ClickAndMortar\RemoteBundle\Service\RemoteService and register a new adapter in the bundle’s DI container.RemoteAdapterInterface.Pre/Post-Transfer Hooks:
// In a service provider
$this->app->booted(function () {
event(new RemoteFileDownloaded('file.txt', './local'));
});
Progress Tracking:
ProgressBar):
use Symfony\Component\Console\Style\SymfonyStyle;
class CustomDownloadCommand extends AbstractCommand {
protected function execute(InputInterface $input, OutputInterface $output) {
$style = new SymfonyStyle($input, $output);
$style->progressStart(100);
// Simulate progress...
$style->progressAdvance(50);
$style->progressFinish();
}
}
config/packages/clickandmortar_remote.yaml:
click_and_mortar_remote:
timeout: 60 # Override globally
.env for sensitive data:
REMOTE_BUNDLE_TIMEOUT=60
Then reference in config:
timeout: '%env(int:REMOTE_BUNDLE_TIMEOUT, 10)%'
php bin/console candm:remote:get ftp user@example.com /files/*.jpg ./local
tar -czf backup.tar.gz /local/files && php bin/console candm:remote:put ftp user@example.com backup.tar.gz /remote/backup.tar.gz
RemoteTransferJob::dispatch('ftp', 'user@example.com', '/file1.txt', './local')->onQueue('remote-transfers');
How can I help you explore Laravel packages today?