Link to home
Start Free TrialLog in
Avatar of MostHated
MostHatedFlag for United States of America

asked on

AS/400 issues trying to use Expect / TCL to connect via SFTP with a password from IBM iseries i/5 with QSH -oPort, etc.

Hello all,
    I am having issues getting connected to an SFTP server using our AS/400, I keep getting the error of :

Permission denied, please try again.                        
Permission denied, please try again.                        
Permission denied (publickey,password,keyboard-interactive).
Connection closed                                            

I tried installing Expect / TCL, following this guide http://www.scottklement.com/expect/ . I installed our private key using ssh-add in my ~/user/.ssh directory, which said it was successful. I am told they were installed properly on the receiving end and added to authorized_keys.

I am not sure if I am missing something though. My connection string looks as follows.

sftp -oPort=10022 username@sftp.domain.com, I also tried sftp -oPort=10022 username:password@sftp.domain.com

I then tried to make a script similar to examples that I saw that look like the following  which I found the example script here :

http://www.scottklement.com/presentations/Setting%20up%20and%20Scripting%20the%20OpenSSH,%20SFTP%20and%20SCP%20Utilities%20on%20IBM%20i.pdf

#!/usr/local/bin/expect -f
set timeout 20
spawn sftp username@sftp.domain.com
expect {
default {exit 2}
"continue connecting (yes/no)?" {send "yes\n"; exp_continue}
"assword:" {send "$env(PASSWORD)\n"; exp_continue}
"sftp>"
}

Open in new window


This gives the error of :

$                                                                                                    
./connect.sh                                                                                         
./connect.sh: 001-0019 Error found searching for command spawn. No such path or directory.           
./connect.sh: 001-0019 Error found searching for command expect. No such path or directory.          
./connect.sh: 001-0019 Error found searching for command default. No such path or directory.         
./connect.sh: 001-0014 Command continue connecting (yes/no)? not found.                              
./connect.sh: 001-0019 Error found searching for command exp_continue}. No such path or directory.   
./connect.sh: 001-0019 Error found searching for command assword:. No such path or directory.        
./connect.sh: 001-0019 Error found searching for command exp_continue}. No such path or directory.   
./connect.sh: 001-0019 Error found searching for command sftp>. No such path or directory.           
./connect.sh: 001-0050 Syntax error on line 9: token "}" not expected.                               

Open in new window


Did I do something wrong with Expect, or do I have to do something specific to actually start the application? If anyone has some insight, I would grearly appreciate it.
SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MostHated

ASKER

It could be that I may just have not properly installed or started Expect tool. I extracted it, it is located in /usr/bin/local. Am I missing something to actually fire it up aside from calling it in the beginning line of a script? It looks like the Expect Tool is just not working properly for some reason? If I go to its location and just try to ./expect, I get Syntax error on line 1: token ")" not expected.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I appreciate the replies. I definitely am hoping they will  do the key pair setup, I already did those steps and sent the public key to them last week (It is a large international EDI Van provider) but have not heard back yet if they are willing to install the key for me and let me use it, which is why I have been trying to go the Expect route. I am not sure if they are willing to change their typical process / setup that they use just for us.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It is SPS Commerce. They had just sent us the Username, Password, and connection URL with a port number.
I think I see what may be part of the issue, I tried to ./configure in the expect folder and it said the below. Though I had downloaded a precompiled one before, but it was only version 5.43, and not 5.45.

 ./configure                                                          
 checking for correct TEA configuration... ok (TEA 3.9)               
 configure: configuring expect 5.45                                   
 checking for Tcl configuration... found /usr/local/lib/tclConfig.sh  
 checking for existence of /usr/local/lib/tclConfig.sh... loading     
 configure: --prefix defaulting to TCL_PREFIX /usr/local              
 configure: --exec-prefix defaulting to TCL_EXEC_PREFIX /usr/local    
 checking for gcc... no                                               
 checking for cc... no                                                
 checking for cc... no                                                
 checking for cl... no                                                
 configure: error: no acceptable C compiler found in $PATH            
 See `config.log' for more details.                                   
 $                                                                    

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have been using that connection string to try and connect, that was what was giving the originally posted error.

Though I have been connecting into the as400 using the i navigators emulation terminal and then typing in QSH to get to a command line once logged in to our VAI application. I will give what you mentioned a go.

** Edit -- What you just mentioned to do worked, I was able to login and I get an sftp>  prompt now.

Edit again. I am getting closer, but putty keeps closing once it tries to connect with the sftp string and then get to the expect { } parts too fast for me to see what it says, is there a way to force it to stay opened?

** Edit once more lol. While I was working on getting the script working, they added my public key for me, so now everything is working great using just the keypairs. : D I appreciate all the help, the knowledge will still come in handy down the road I am sure, and I am sure this will help out some fellas down the line. Enabling SSH and doing it from putty seems to have been the majority of the issue.
Lol.  Happy you got something working!