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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to log in SFTP server [with username, password]
# 1  
Old 07-15-2013
Tools 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 Smilie
# 2  
Old 07-15-2013
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'

Code:
 
So pass.txt will contain
 
olleho

Code:
 
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.

Code:
 
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.
# 3  
Old 07-15-2013
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:
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
# 4  
Old 07-15-2013
The only way is to use key authentication.
This User Gave Thanks to millan For This Post:
# 5  
Old 07-15-2013
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:
Code:
cd pe_ase/data/vax
ls
bye

But it does not work, the server is connected but never do anything after that:
Code:
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i su automaticaly in same server with different username and same password?

Hi I am new to shell scripting, Can you please help me in writing a script that can switch user in same server with different user name and same password. I want to perform some functional task in a particular user and need to switch user and perform same activity in another user and so on ... ... (4 Replies)
Discussion started by: Dew
4 Replies

2. Shell Programming and Scripting

How to send Two different password in Single script, having same username..?

Hi Team, i want to input two password for single node like pass1/pass2 one of the pass1 is working some node and pass2 is working for some nodes . For nodes having pass1 i have to run different script and for nodes having pass2 i have to run different script Sooo how can put two pass... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

3. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

4. HP-UX

Connect to remote server using sftp with password define within command/script

I am trying to connect to remote server in hp-ux, using sftp command (using sftp username@ip and password ) able to connect to remote server but, in this case sftp prompt for password and user need to manually enter it. I want sftp can read a password define in script or from file, so it can... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

Auto Script to Access external Server via SFTP using Password and Key

Hello All, I am stuck! I have access to an external server via SFTP. In order to access the external server I was given a specific port, password, and a ppk. I would to create a script on my server end that can I can setup as a corn job, that will connect to the external server and... (1 Reply)
Discussion started by: kingr008
1 Replies

6. UNIX and Linux Applications

Regarding NFS server username/password authentication

Hi; I had set up NFS server in one ubuntu box and mounted few directories using it. In order to access those directories across the network i m using j-ftp(an open source java network client) from other boxes in the same network.I am able to view my mounted directories in the server through it.... (1 Reply)
Discussion started by: ajaypadvi
1 Replies

7. AIX

SFTP from one server to another with password

All, Is there a possibility to sftp a file from one AIX server to another AIX server with password? I do not want to use public or private key option as we would have required privileges for creating the keys. So Please provide the needful with a sample script. Thanks in Advance, Vijayakumar S... (2 Replies)
Discussion started by: kuppu.uncle
2 Replies

8. UNIX for Advanced & Expert Users

Login through SFTP using username and password

Hi All, 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. I am using GNU/Linux server. Please advise me !!!... (4 Replies)
Discussion started by: sparks
4 Replies

9. Solaris

i wanto hardcode password for a username to ssh to a server using script

Dear all i want to ssh to a server via running a shell script with a username and i want to hard code the password for that particular username can u help me please Thank u Naree (8 Replies)
Discussion started by: naree
8 Replies

10. Shell Programming and Scripting

username password in script

Can we write a script to telnet to a unix server from unix with the username and password hardcoded in the script?? something like ssh a@b -p password ??? (5 Replies)
Discussion started by: roshanjain2
5 Replies
Login or Register to Ask a Question