Webform export to CSV programmatically I'm looking to write a module that automatically uploads the submissions of a webform to an ftp server every week or so.

I'm looking for the recommended way to use the CSV export plugin that comes with the WebForm module to render a csv file to a string. I would want to set the following options:


separator (default is , but should be ; because Europe)
start date and end date of submissions (weekly export)


I see there are a lot of classes and configuration options available, but I'm not sure about the best way to string them together to achieve what I need.
After looking at the drush webform-export code I came up with the following code sample. 
It appears to work, however jrockowitz advises me that using drush straight up should be the best solution. I'm sure there's something wrong with the following code. For one, it probably breaks when the export is too large. 

$webform_id = 'easykit_vip_formulier';
$webform = \Drupal\webform\Entity\Webform::load($webform_id);
$submission_exporter = \Drupal::service('webform_submission.exporter');
$export_options = $submission_exporter-&gt;getDefaultExportOptions();

$export_options['delimiter'] = ';';
$export_options['multiple_delimiter'] = ',';
$export_options['range_type'] = 'date';
$export_options['range_start'] = '2018-02-18';
$export_options['range_end'] = '2018-02-26';

$submission_exporter-&gt;setWebform($webform);
$submission_exporter-&gt;setExporter($export_options);
$submission_exporter-&gt;generate();
$file_path = $submission_exporter-&gt;getExportFilePath();

print file_get_contents($file_path);

unlink($file_path);