Automation & scripting
Your first automated transfer
Build a script that uploads a folder, test it by hand, then let the GUI write one for you.
This tutorial builds a small job that uploads the files of a local folder to a web server. By the end you have a script file, a wrapper you can schedule, and a log to read when something fails.
1. Save the site in the GUI
Section titled “1. Save the site in the GUI”Open linscp, create a site in the Site Manager for files.example.org
with user deploy, and log in once. Accept the host key when asked. The site
and the key are now stored in the shared configuration, so the script can
refer to the site by its name, say webserver.
2. Write the script
Section titled “2. Write the script”Create ~/jobs/upload.txt:
# Upload the built siteopen webservercd /var/www/htmllcd /home/alice/site/publicput -neweronly *exitEach line is one command. lcd sets the local folder, cd the remote one.
put -neweronly sends only files that are new or changed since the last
run. See put for its other switches.
3. Run it by hand
Section titled “3. Run it by hand”linscp-cli /script="$HOME/jobs/upload.txt" /log="$HOME/jobs/upload.log"echo "exit code: $?""C:\Program Files\linscp\linscp-cli.exe" /script=C:\Users\alice\jobs\upload.txt /log=C:\Users\alice\jobs\upload.logecho exit code: %ERRORLEVEL%linscp-cli prints each command’s progress. An exit code of 0 means every
command succeeded; 1 means one failed and the script stopped there. Open
the log to see the protocol-level detail behind a failure.
4. Wrap it for scheduling
Section titled “4. Wrap it for scheduling”A small shell script keeps the paths in one place and is what you hand to cron or a systemd timer:
#!/bin/shset -ucd "$HOME/jobs" || exit 1linscp-cli /script=upload.txt /log=upload.log /loglevel=0status=$?[ "$status" -eq 0 ] || echo "upload failed with code $status" >&2exit "$status"Make it executable with chmod +x ~/jobs/upload.sh. The
scheduling page shows how to run it every night.
Let the GUI write the script
Section titled “Let the GUI write the script”linscp can generate the commands for a session or a transfer you set up with the mouse:
- For a connection: Tabs › Generate Session URL/Code…, or Manage › Generate Session URL/Code… in the Site Manager.
- For a transfer: start an upload or download and press Generate Code…
in the transfer dialog. The result includes the
putorgetline with the transfer settings you chose.
On the Script tab, choose the Script file format to get text you can
save as upload.txt directly. Generated output also includes the host key,
so the script works without a stored site.