System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Expect/SFTP fails when password contains '#'

SOLVED
Go to solution
Nikon MIS
Occasional Contributor

Expect/SFTP fails when password contains '#'

I am attempting to automate an sftp session with expect.
The vendor I am downloading files from has assigned me
an id/password and the password contains a #.
I have set up a test in my office (two hp-ux servers) and
it works fine except when there is a # in the password.
I have tried escaping the # with \# and even using an
octal representation, \043, but the login still fails.

output with debug, password is #abc123....

expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) " sftp2\r\n331 Password required for sftp2.\r\nPassword:"

send: sending "#abc123" to { exp7 }
tty_raw_noecho: was raw = 0 echo = 1
spawn id exp0 sent <\r>
spawn id exp7 sent <\r\n>

spawn id exp7 sent <530 Login incorrect.\r\n>
530 Login incorrect.
spawn id exp7 sent
Login failed.

I know I could request the password contain no # but I am
curious why this fails. Thanks.
george drew
4 REPLIES
Pete Randall
Outstanding Contributor

Re: Expect/SFTP fails when password contains '#'

From the man page on passwd:

"WARNINGS
Avoid password characters which have special meaning to the tty driver, such as # (erase) and @ (kill). You may not be able to login with these characters."

That seems to be exactly what you're experiencing!


Pete

Pete
OldSchool
Honored Contributor
Solution

Re: Expect/SFTP fails when password contains '#'

ok, take a look at this.

http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1214938

I think you're on the right track w/ the "escape"....but you may need more than one. Depends on how the shells and expect are interacting..something like '\\\#abc123' or '\\\\#abc123' perhaps?

The next hurdle would be, what happens at the vendor's login. My guess is that it will behave differently, since they sent you a password with a "#" in it to begin with.

If you login via telnet from HP to HP at the office, a single '\' should suffice, so doubling it in the script *ought* to get it. If it does, then what happens at the vendor server? does in require 0 or 1 escapes?
Nikon MIS
Occasional Contributor

Re: Expect/SFTP fails when password contains '#'

I forgot to mention a very important fact:
when logging in interactively (without expect) sftp takes the # OK.

However, when using the double escape, \\#abc123, in the script, dbug showed \#abc123 being sent and the login worked!
Thanks!
george drew
pashisbey
Occasional Visitor

Re: Expect/SFTP fails when password contains '#'

Thanks! Worked for me.  I had a hashtag in my password and the sftp expect script was failing. But after escaping it out with two slashes it works. 

 

Changed my#password

to: my\\#password

 

and it works!

 

Thanks much!

Phil