diff --git a/rule/ftpsyncfiles/rule_class.php b/rule/ftpsyncfiles/rule_class.php index 8eb073a6..509dcf31 100644 --- a/rule/ftpsyncfiles/rule_class.php +++ b/rule/ftpsyncfiles/rule_class.php @@ -205,21 +205,33 @@ private function download_files(int $did): void { $filedata ); echo "Downloaded $filename successfully." . PHP_EOL; - // Delete the file from the remote server using cURL. - $deletech = curl_init(); - curl_setopt($deletech, CURLOPT_URL, $remotepath); - curl_setopt($deletech, CURLOPT_QUOTE, array("rm ".escapeshellarg("$remotepath")); - $deleteresult = curl_exec($deletech); - curl_close($deletech); + } else { + echo "Failed to download $filename." . PHP_EOL; + } + echo json_encode(curl_getinfo($filehandle)); + curl_close($filehandle); + } + } + foreach ($remotelist as $line) { + $parts = preg_split('/\s+/', trim($line)); + $filename = end($parts); + if (!empty($filename) && $filename !== '.' && $filename !== '..') { + // Delete the file from the remote server using cURL. + curl_setopt($ch, CURLOPT_QUOTE, ["rm " . escapeshellarg($filename)]); + $deleteresult = curl_exec($ch); + if ($deleteresult === false) { + var_dump(curl_errno($ch),curl_error($ch)); + curl_setopt($ch, CURLOPT_QUOTE, ["rm " . $filename]); + $deleteresult = curl_exec($ch); if ($deleteresult === false) { echo "Failed to delete $filename on the remote server." . PHP_EOL; - } else { - echo "Deleted $filename successfully." . PHP_EOL; + curl_setopt($ch, CURLOPT_QUOTE, ["rm \"$filename\""]); + $deleteresult = curl_exec($ch); + var_dump(curl_errno($ch),curl_error($ch)); } } else { - echo "Failed to download $filename." . PHP_EOL; + echo "Deleted $filename successfully." . PHP_EOL; } - curl_close($filehandle); } } }