Bug 33308 - Add ability to to use SFTP with runreport.pl
Summary: Add ability to to use SFTP with runreport.pl
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Jake Deery
QA Contact: Testopia
URL:
Keywords:
Depends on: 40811
Blocks:
  Show dependency treegraph
 
Reported: 2023-03-22 16:01 UTC by Liz Rea
Modified: 2025-11-06 20:32 UTC (History)
5 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 33308: Add S/FTP upload support to runreport.pl (8.72 KB, patch)
2025-11-04 09:07 UTC, Jake Deery
Details | Diff | Splinter Review
Bug 33308: Add S/FTP upload support to runreport.pl (8.77 KB, patch)
2025-11-06 20:32 UTC, Andrew Fuerste-Henry
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Liz Rea 2023-03-22 16:01:32 UTC
It would be very awesome to be able to specify a sftp/ftps target with the cronjob runreport.pl job, to complement the ability currently available to email the report somewhere. 

Some kind of secure solve for "allowing the koha user to automatically accept the hostkey" on the first connection would also be nice, but not a requirement.
Comment 1 Katrin Fischer 2023-03-23 22:34:35 UTC
I like the idea, but maybe a workaround: would be using the 'access files' tools and a directory on the Koha server work? It would limit access to Koha staff users with the right permission set.
Comment 2 Liz Rea 2023-03-27 22:39:26 UTC
We do this in some places, but by and large our partners do not like this approach for a few reasons:

They often have to send things other places without human intervention, on a schedule.
The UX of the access_files is very poor (no directory structures allowed, cannot remove files themselves, among other things.)
They have workflows that involve 3rd party vendors who require sftp/ftp deliveries of files.

Right now, we generate the files and use other tools to deliver the files, which works but is very labor intensive when you have many of them to administer.
Comment 3 Katrin Fischer 2023-04-04 09:31:24 UTC
Thx for the reply, Liz, that makes sense.
Comment 4 Jake Deery 2025-11-04 09:07:21 UTC
Created attachment 189005 [details] [review]
Bug 33308: Add S/FTP upload support to runreport.pl

This patch adds S/FTP upload support to runreport.pl by adding additional command-line flags that will, when utilised, deposit a report onto the configured S/FTP Server.

== TO TEST ==
a)  Goto /cgi-bin/koha/admin/file_transports.pl?op=add_form
b)  Configure an S/FTP Server
    *)  If one needs an S/FTP Server to utilise, contact me directly
c)  Configure an SQL report under Reports > Create from SQL
    *)  If you're stuck, you can use `SELECT * FROM items` to select every item in k.t.d to report on
== APPLY PATCH ==
d)  Run `./misc/cronjobs/runreport.pl` without arguments
    *)  Notice `--sftp-dest-id` and `--filename`
    *)  `--sftp-dest-id` specifies the ID of the configured server to use, which can be garnered from the URL when editing the server (look for the file_transport_id parameter)
    *)  `--filename` optionally specifies what the file should be called when uploaded, and can be customised with bash variables if necessary
e)  Run `./misc/cronjons/runreport.pl --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named report(id)-(date).csv
    *)  Notice that the outputted file contains a CSV-formatted report
f)  Run `./misc/cronjobs/runreport.pl --format html --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named report(id)-(date).html
    *)  Notice that the outputted file contains an HTML-formatted report
g)  Run `./misc/cronjons/runreport.pl --filename custom.csv --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named custom.csv
    *)  Notice that the outputted file contains a CSV-formatted report
h)  Run `./misc/cronjons/runreport.pl --format html --filename custom.somehtml --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named custom.somehtml
    *)  Notice that the outputted file contains an HTML-formatted report
== SIGN OFF ==
Comment 5 Andrew Fuerste-Henry 2025-11-06 20:32:13 UTC
Created attachment 189230 [details] [review]
Bug 33308: Add S/FTP upload support to runreport.pl

This patch adds S/FTP upload support to runreport.pl by adding additional command-line flags that will, when utilised, deposit a report onto the configured S/FTP Server.

== TO TEST ==
a)  Goto /cgi-bin/koha/admin/file_transports.pl?op=add_form
b)  Configure an S/FTP Server
    *)  If one needs an S/FTP Server to utilise, contact me directly
c)  Configure an SQL report under Reports > Create from SQL
    *)  If you're stuck, you can use `SELECT * FROM items` to select every item in k.t.d to report on
== APPLY PATCH ==
d)  Run `./misc/cronjobs/runreport.pl` without arguments
    *)  Notice `--sftp-dest-id` and `--filename`
    *)  `--sftp-dest-id` specifies the ID of the configured server to use, which can be garnered from the URL when editing the server (look for the file_transport_id parameter)
    *)  `--filename` optionally specifies what the file should be called when uploaded, and can be customised with bash variables if necessary
e)  Run `./misc/cronjons/runreport.pl --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named report(id)-(date).csv
    *)  Notice that the outputted file contains a CSV-formatted report
f)  Run `./misc/cronjobs/runreport.pl --format html --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named report(id)-(date).html
    *)  Notice that the outputted file contains an HTML-formatted report
g)  Run `./misc/cronjons/runreport.pl --filename custom.csv --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named custom.csv
    *)  Notice that the outputted file contains a CSV-formatted report
h)  Run `./misc/cronjons/runreport.pl --format html --filename custom.somehtml --sftp-dest-id 1 1`
    *)  Notice the script outputs nothing, indicating success
    *)  On your S/FTP server, notice a report now named custom.somehtml
    *)  Notice that the outputted file contains an HTML-formatted report
== SIGN OFF ==

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>