I want to login to a server through SFTP by giving username and password, in an automated script.
I know that this can be done through public key authentication, but my requirement is to login ONLY through username and password.
Was this requirement forced down your throat by crazed management? I've heard 'security' used as an excuse for the complete and total lack of it far too many times; storing passwords in plaintext form is a very bad idea. It's extremely hard to protect them.
If you absolutely have to, the 'expect' tool may help you, but it's a kludge.
Actually, i have a script which blocks an IP, which is trying to connect to a server making invalid login attempts.And these attempts are made n number of times in a single minute. This is causing in high CPU consumption and is causing problem to the valid users who are connecting to that server
To test this script, i want an other script which can make login attempts to a server continuosly and this should be through SFTP and that is the reason i need to give the password in the script.
It sounds like what you really need is firewall to block your problem SFTP connections. You said you're using Linux, look into the firewall that comes with it. (which I think is iptables - I don't use linux firewalls so I'm not 100% certain anymore).