How to scp to transfer file by sshpass

I tried to send file from raspberry pi to openwrt by using shellscript written like

sudo sshpass -p raspberry scp /home/pi/a.txt root@

PS I create new directory in openwrt called recv
As a result, no file was transfer to openwrt. What should I fix it. Thank you.

First test the plain scp command, so that you have got that part right.

To me it looks strange that your target path does not start with / to be an absolute path, but starts with "root/recv/". Is that correct?

To which exact directory you are trying to copy into?

I tried scp command only... It worked. For directory: As you said it is /root.recv/aa.txt. I wrote it wrong on the forum. But in my script it is the correct path. It still not working.

Can you share your script and the error that shows its not working

my script is

sudo sshpass -p raspberry scp /home/pi/a.txt root@

it has no output and no error

So I tried using another script.

sudo scp pi@raspberrypi:/home/pi/a.txt root@

At first, this script worked, but now it output like permission denied, please try again.
connection closed by port 22
lost connection

PS I also did chmod +x

when you run this scp command on the shell does it prompt to enter password ?

Why not use a ssh key instead of sshpass?

1 Like

Yes, it does.

I just want to make shellscript to transfer file. Actually, just a little project... not focus much about security.

Your script does not have the provision to enter password, adjust that it should work.

Is "raspberry" the password of the OpenWrt device?

What happens if you change it to this:
sudo scp /home/pi/a.txt root@

Thank you so much. I input wrong password... I input rpi password. And when type it correctly it should be

sudo sshpass -p 'openwrt_password' scp /home/pi/a.txt root@

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.