Reputation: 2287
I'm trying to write a shell script to transfer files to a remote windows machine which is running a ultra simple sftp server . Its a light version from coreftp. So i don't have the option of using public key authentication.
From the Linux end its a stripped down version for non intel platform , So if i want to use "expect" i cant install expect/tcl/tk. And this is for testing purpose and i would like to input the password from Shell script. Is there a method available?
#!/bin/sh
HOST='10.x.x.x'
USER='user'
PASSWD='passwd'
sftp $USER@$HOST
Is it not possible to input password from shellscript without using any tool ?
Upvotes: 2
Views: 1312
Reputation: 4484
This page contains a simple demo program in C to create pseudo-terminal that can interact with application that needs password (More accurately, applications that needs a terminal) like ftp, sftp client, etc.. The reference session of the same page also mentioned lpty, which is another more complete utility program that you can use to run your program on pseudo-terminal.
In short, you need a program that can handle pseudo-terminal, to do your task. Be it expect, perl with expect module, direct C programming mentioned above, or lpty, yet another pseudo-terminal program. Or, if your Linux kernel supports /dev/ptmx, and /dev/pty/, you can create pseudo-terminal by just open and access the device files (From shell script, maybe, but I am not sure). I doubt your simple Linux on ARM supports that though...
Porting lpty should be easier than expect.
Upvotes: 0
Reputation: 10234
There are several alternatives:
You can use sshpass to automate the password authentication.
The SFTP client from the Putty package (psftp) accepts the password from the command line (though doing that is not completely secure).
Then you can use some scripting language with support for SFTP. If you go that route, don't just use some expect-like module to automate the password authentication, instead use some module that implements the SFTP protocol by itself, that will make your like easier specially if you want to perform error checking.
Upvotes: 1
Reputation: 1049
You could use expect..
expect -c 'spawn sftp [email protected]; expect password; send "your-password\n"; interact'
Upvotes: 0