Sftp automate

hi,

I am trying to automate a file download process using sftp. There is some logic to download files.

1) I need to login to destination server and then go to folder.
2) find list of files and count
3) using list of files I need to eliminate three selective files and download remaining files to local server.

I tried using ssh user@servername#port to get list of files and file count. However passwordless is not enabled with ssh, but sftp works below.

sftp user@servername#port
sftp>

Could someone help to script this?

Thanks in advance
Milo

This is asked quite often in this forum. Use the search function with maybe "automate sftp" or just check the 5 suggested links at the bottom of this thread.