I’m trying to figure out how to leverage drupals native functions to copy a folder to a destination. I’ve found the class called FileTransfer, which has a method called copyDirectory. The problem is that the FileTransfer class is abstract and I can’t figure out how to reach that method.
Here’s the code I’m using
<?php
function generator_form_submit($form, $form_state) {
$modules_folder = 'sites/all/modules/custom/';
$model_folder = drupal_get_path('module', 'generator') . '/model';
class transfer {
function copy() {
FileTransfer::copyDirectory($model_folder, $modules_folder);
}
}
$transfer = new transfer;
$transfer->copy($model_folder, $modules_folder);
}
?>
This throws me the error “Call to undefined method transfer::sanitizePath()”, since the method uses $this. I’ve tried many ways to get it working, but the code I’m posting here is the best attempt I’ve got.
Does anyone know how to do this?
The
FileTransferclass is an abstract class specifying what is required to perform a file transfer, it can’t actually perform one itself without a subclass implementing various methods. Drupal provides the subclassesFileTransferFTP,FileTransferLocalandFileTransferSSH, which I believe are non-abstract. You probably should use whichever of these is appropriate.