PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Novice needs using Expect to automate sftp
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Novice needs using Expect to automate sftp

Réponse
 
LinkBack Outils de la discussion
Vieux 13/07/2007, 16h03   #1
rsine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Novice needs using Expect to automate sftp

I have been struggling with a project that requires me to use sftp.
After working through all the issues getting sftp working on AIX 5.3,
I now need to automate the sftp process. This appears harder than it
should be. It appears that getting past the password prompt is a
frustration everyone runs up against. After much reading, I thought
Expect was the key and I installed it. Unfortunately, it does not
seem to be working. Here is what I am trying:

# /usr/bin/expect << EOF
> spawn sftp username@sftp.site.com
> expect "password:"
> send "my_password"
> expect "sftp>"
> send "ls"
> expect "sftp>"
> send "quit"
> EOF


And here is what I am getting:

spawn sftp username@sftp.site.com
Connecting to sftp.site.com...
username@sftp.site.com's password: #

As you can see, I am still being prompted for the password. What am I
doing incorrectly?

-Thanks

  Réponse avec citation
Vieux 13/07/2007, 17h51   #2
Michael Heiming
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Novice needs using Expect to automate sftp

In comp.unix.shell rsine <rsine@stationeryhouse.com>:
> I have been struggling with a project that requires me to use sftp.

[..]

> As you can see, I am still being prompted for the password. What am I
> doing incorrectly?


Simply setup ssh keylogin and you do not need a password at all:

$ sftp localhost
Connecting to localhost...
sftp>

It is explained in the ssh man page:

man ssh
/authorized_keys

And there are probably hundreds of guides online accessible
through a web search how to set this up. Extra points for running
ssh-agent, though you should do better even with an empty pass
phrase then putting the password in a file.

Good luck

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 13: we're waiting for [the phone company] to fix
that line
  Réponse avec citation
Vieux 13/07/2007, 18h04   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Novice needs using Expect to automate sftp

On Fri, 13 Jul 2007 08:03:19 -0700, rsine
<rsine@stationeryhouse.com> wrote:
>
>
> I have been struggling with a project that requires me to use sftp.
> After working through all the issues getting sftp working on AIX 5.3,
> I now need to automate the sftp process. This appears harder than it
> should be. It appears that getting past the password prompt is a
> frustration everyone runs up against. After much reading, I thought
> Expect was the key and I installed it. Unfortunately, it does not
> seem to be working. Here is what I am trying:
>
> # /usr/bin/expect << EOF
>> spawn sftp username@sftp.site.com
>> expect "password:"
>> send "my_password"

send "my_password\r"


--
Police are unsure if the same wookie is involved in Sunday's assault.
  Réponse avec citation
Vieux 13/07/2007, 18h17   #4
rsine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Novice needs using Expect to automate sftp

On Jul 13, 1:04 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On Fri, 13 Jul 2007 08:03:19 -0700, rsine <rs...@stationeryhouse.com> wrote:
>
> > I have been struggling with a project that requires me to use sftp.
> > After working through all the issues getting sftp working on AIX 5.3,
> > I now need to automate the sftp process. This appears harder than it
> > should be. It appears that getting past the password prompt is a
> > frustration everyone runs up against. After much reading, I thought
> > Expect was the key and I installed it. Unfortunately, it does not
> > seem to be working. Here is what I am trying:

>
> > # /usr/bin/expect << EOF
> >> spawn sftp usern...@sftp.site.com
> >> expect "password:"
> >> send "my_password"

>
> send "my_password\r"
>
> --
> Police are unsure if the same wookie is involved in Sunday's assault.


Bill,

I think my issue is with the password. The vendor created one with "$
$" in it ala AbCDE$$123. I know the "$" symbol has a special meaning
for Unix. How can I pass the "$$" in a password? Enclosing the
password in quotes did not .

  Réponse avec citation
Vieux 13/07/2007, 18h50   #5
rsine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Novice needs using Expect to automate sftp

On Jul 13, 1:17 pm, rsine <rs...@stationeryhouse.com> wrote:
> On Jul 13, 1:04 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
>
>
>
>
>
> > On Fri, 13 Jul 2007 08:03:19 -0700, rsine <rs...@stationeryhouse.com> wrote:

>
> > > I have been struggling with a project that requires me to use sftp.
> > > After working through all the issues getting sftp working on AIX 5.3,
> > > I now need to automate the sftp process. This appears harder than it
> > > should be. It appears that getting past the password prompt is a
> > > frustration everyone runs up against. After much reading, I thought
> > > Expect was the key and I installed it. Unfortunately, it does not
> > > seem to be working. Here is what I am trying:

>
> > > # /usr/bin/expect << EOF
> > >> spawn sftp usern...@sftp.site.com
> > >> expect "password:"
> > >> send "my_password"

>
> > send "my_password\r"

>
> > --
> > Police are unsure if the same wookie is involved in Sunday's assault.

>
> Bill,
>
> I think my issue is with the password. The vendor created one with "$
> $" in it ala AbCDE$$123. I know the "$" symbol has a special meaning
> for Unix. How can I pass the "$$" in a password? Enclosing the
> password in quotes did not .- Hide quoted text -
>
> - Show quoted text -


Thanks for all the . After more research, I discovered
autoexpect. Using this tool, I was able to capture all that I was
executing. Looking at the autoexpect file, I found the password
needed the dollar signs entered as "\$\$" and the "\r" needed to be
concatenated to the data (I was leaving a space between).

For all those novices like me, here is what I found to work:

expect << EOF
spawn sftp username@sftp.site.com
expect "password:"
send -- "my_pa\$\$word\r"
expect "sftp> "
send -- "ls\r"
expect "sftp> "
send -- "exit\r"
EOF


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h07.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16813 seconds with 13 queries