I am trying to send a file to my phone using the SFTP protocol in my home network.
Though I can easily send the file to my phone using the put command in FTP, but I want to automate the task.
So I wrote this script:
#! /bin/bash
#Capture and share screenshot to my phone
gnome-screenshot
cd /home/prm/Pictures
FILE="$(ls -Art | tail -n 1)" #To get the last created file
sftp sftp://192.168.1.2:1753/primary/DCIM/Screenshots
put /home/prm/Pictures/$FILE
I am able to connect to my phone and required directory, but I don't how to upload. Please help!
After updating the code to:
#! /bin/bash
#Capture and share screenshot to my phone
gnome-screenshot
cd /home/prm/Pictures
FILE="$(ls -Art | tail -n 1)" #To get the last created file
echo $FILE
sftp sftp://192.168.1.3:1761/primary/DCIM/Screenshots -b <<<"put /home/prm/Pictures/$FILE"
I got the following output:
prm@prm-2018-02:~/Documents/Anubhav/Bash$ ./capture.sh
Screenshot from 2020-06-04 22-38-27.png
Connected to 192.168.1.3.
Fetching /primary/DCIM/Screenshots/ to -b/Screenshots
Cannot download non-regular file: /primary/DCIM/Screenshots/
I also tried adding -r flag:
sftp -r sftp://192.168.1.3:1761/primary/DCIM/Screenshots -b <<<"put /home/prm/Pictures/$FILE"
But this copied screenshots from my phone to the local system.
prm@prm-2018-02:~/Documents/Anubhav/Bash$ ./capture.sh
Screenshot from 2020-06-04 22-51-51.png
Connected to 192.168.1.3.
Fetching /primary/DCIM/Screenshots/ to -b/Screenshots
Retrieving /primary/DCIM/Screenshots
/primary/DCIM/Screenshots/Screenshot_20200604-225146.jpg 100% 176KB 549.6KB/s 00:00