2

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 ?

m4n07
  • 2,267
  • 12
  • 50
  • 65
  • I assume you also can not install an `expect` module for perl, python, or some other language? – jordanm Jan 25 '13 at 05:21
  • yes, I cannot install other packages. – m4n07 Jan 25 '13 at 05:44
  • expect will compile for most architectures. – jordanm Jan 25 '13 at 05:46
  • Yes Its time consuming to cross compile the expect and the dependency package TCL/TK . – m4n07 Jan 25 '13 at 05:50
  • "Cannot install" as in "lack root access" or "lack a home directory"? Many Perl and Python packages can easily be installed in your home directory. – tripleee Jan 25 '13 at 11:17
  • As i have to cross compile for ARM and place it . – m4n07 Jan 25 '13 at 11:36
  • What protocol version is being used? Exactly what features are supported by the target? Does it support host based or rhosts authentication? Do you have any control over its configuration? – Keith Jan 26 '13 at 03:15
  • Its a simple ultra light sftp server. You dont have to install any. Just start the exe, it provides password based authentication – m4n07 Jan 26 '13 at 03:41
  • possible duplicate of [sftp to windows machine from linux using key based authentication](http://stackoverflow.com/questions/14534690/sftp-to-windows-machine-from-linux-using-key-based-authentication) – glenn jackman Jan 26 '13 at 07:12
  • @glenn , This question focuses on non key based authentication using a ultra simple sftp server. The other one is based on public key authentication. I'm trying different methods as i'm not getting any breakthrough. Thanks – m4n07 Jan 26 '13 at 07:33

3 Answers3

1

There are several alternatives:

  1. You can use sshpass to automate the password authentication.

  2. The SFTP client from the Putty package (psftp) accepts the password from the command line (though doing that is not completely secure).

  3. 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.

salva
  • 9,943
  • 4
  • 29
  • 57
0

You could use expect..

expect -c 'spawn sftp root@your-domain.com; expect password; send "your-password\n"; interact'
bsmoo
  • 949
  • 4
  • 10
  • 23
  • Thanks for your answer. But when i was trying i was in a position where i can't use expect. – m4n07 Feb 07 '13 at 20:15
  • No worries, as far as I'm aware it's not possible in shellscript. Best bet would be ssh keys / expect – bsmoo Feb 12 '13 at 15:57
0

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.

Robin Hsu
  • 4,164
  • 3
  • 20
  • 37