Script to log in SFTP server [with username, password]

Hi, everyone, I am trying to write a script to login automatically using username and password to an sftp server (the key authentication has been disabled so I cannot use that method).
I tried to search online for a solution and found a way using "expect" but my boss does not want me to use expect since the passwords need to be provided in plain-text.
I am a newbie about this sftp server. Please help out, thanks alot :slight_smile:

You can keep the password in reverse manner in a text file.Then in the script determine the password.

For example

Lets say your password 'hello'

 
So pass.txt will contain
 
olleho
 
In the script you can source the pass.txt as below.
. pass.txt 

In your script ypu can calcualte the exact password, which a layman cannot understand , but yes person handy in scripting can do.

 
for entry in `echo $PASS | fold -w1`
 do
  FINALPASS=$entry$FINALPASS
 done
 echo $FINALPASS

Then u can use the password as $FINALPASS in sftp command.

Hi, thanks for your reply, but what I want is not really the way to teak the password but just the script to login to sftp server automatically (like just run the script). I tried to use this "expect" code:

#!/usr/bin/expect

spawn sftp -b [cmdFile] [username]@[servername]
expect "password:"
send "[my password]\n";
interact

But my boss does not want me to use "expect" so if there other way I can log in without "expect" I would really appreciate it (I know it is very not wise to use pass and username in SFTP, but the server is that way, I can not change it T___T).
Thanks for your hep

The only way is to use key authentication.

Hi, so since you guys say there is no other way, I just write the code using expect, it works seems to be fine but it does not call up the cmdFile, so basically the code is the same as above, here is the trial cmdFile that I wrote:

cd pe_ase/data/vax
ls
bye

But it does not work, the server is connected but never do anything after that:

spawn sftp -b [cmdFile] [username]@[servername]
Connecting to [servername]...
[username]@[servername]'s password:
sftp>

Can anyone point out the problem with my code, is the cmdFile have any problem, thanks ,oh for the cmdFile I code in the whole file path so that should not be the issue, thanks