SFTP to send file with bash script

You said that you are not interested in other tools, but scp is a much better choice for unattended file transfers. Here is an scp example:

scp test.txt root@remote:/root/dropoff

I know this is an old one, but you can also pass arguments to a command with a Here Document

You can put the following into a script:

# The following is called a HERE document
sftp <user>@<remote> << SOMEDELIMITER 
  put test.txt
  ... # any commands you need to execute via sftp
  quit
SOMEDELIMITER

each additional command will be fed into the command preceeding the << and SOMEDELIMTER can be anything you want it to be.

scp is a great option, however sftp was the only tool I was able to get working when pushing from linux to windows and you're stuck using FreeSSHD in service mode!

Tags:

Sftp

File

Bash

Send