Use of sftp client in ash script

has anyone used sftp client in ash script? How can I pass users password to sftp?

Thanks in advance,

Best practice for ssh logins from scripts is using keys, not passwords. Restricting the key to a specific command is also recommended.

As sftp is typically used interactively, you might want to consider scp or rsync depending on the sizes of the files, directory structure, and how often they change with time.


Hi Jeff,
thanks for your answer.
I know that keys are better, but I have no space remaining for install more things and this security level is no relevant for this data.
I tryed scp and saw that there isn't an option for password too.

Scripting SSH password authentication is too troublesome.
It requires sshpass or expect which are not even packaged for OpenWrt.
So better use public key authentication.

1 Like

A rather complex entry in authorized_keys or the appropriate file on one of my machines is 300 bytes.

An ed25519 public key is around 100 bytes, the private key is under 500 bytes.

So for either the source or the target machine, it's under 500 bytes.

If you're that tight on space, it would seem like you're going to have even more problems if you're copying files.