WinSCP is one of those tools that makes my Windows-life much more useful. I was originally planning on using syncthing, but for my purposes this was proving to be not a great match.
I needed to copy files from our Windows/Samba shares over to the paperless-ngx server I recently spun up (side note, this is amazing for saving shipping docs, customer PO’s, and other pdfs the org creates). Unfortunately, paperless-ngx will delete the uploaded PDF (located in the consume directory) once it’s been ingested into the system. This tells syncthing “hey, the file is missing, so re-upload it”. Repeat. The good thing is that paperless will NOT keep adding the files as duplicates. The bad thing is that the files now live in several places, eating up precious disk space.
I also did not want non-PDF’s to appear in paperless. Since this was a new project, I also didn’t want to copy any documents older than 30 days (we have 8+ years of archival data). Enter winscp.com – not the URL, but the CLI application.
I created a batch file with the following – obviously change to fit your needs. I should note that SCP requires the hostkey to be setup; this can be found by using the WinSCP GUI, connecting to the paperless-ngx server, and then right-click on the connection tab and select “Generate session URL/code” (it also provides the basis for the script below).
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\temp\Winscp_ShippingComputer_Sync.log" /ini=nul ^
/command ^
"open scp://USERNAME:PASSWORD@10.101.110.16/ -hostkey=""ssh-ed25519 255 03rzYT4K2ufZ2yY3cG4Z5/thG8/dB3UbTi9F7ja9uHY""" ^
"synchronize remote "Y:\Shipping_Scans" "/home/linuxuser/paperless-ngx/consume" -rawtransfersettings ExcludeHiddenFiles=1 -filemask=""*.pdf>=30D""" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%