problem with connecting sftp server(urgent please)

Hi all,

I have command to connect gateway server
iam in home directory/> ssh root@mrp-gateway
root@mrp-gateway:/root> sftp -v msgGoogle@126.132.45.123
sftp/>dir
upload --> folder
sftp/upload/ls
-------------
8990.txt
kittu.txt
8989.txt

i have an requirement to print files list which contain upload folder in the sftp server.

connectSFTP.sh
--------------------
#!/bin/bash
sftpList=`ssh root@mrp-gateway && sftp -v msgGoogle@126.132.45.123 && cd \upload\ && ls`
echo $sftpList

but this command is not working
can any one help me how to solve this issue.

Your script is executing each of the commands seperated by && in order. It's not passing the additional commands to the first as it should.
As a result, your script is first ssh'ing to mrp-gateway, then once that ssh session finishes (ie it'll sit there until it gets logged out) it then attempts an sftp to 126.132.45.123 from the original server (not from the gateway).
Once that sftp session ends (or fails to connect), it will attempt to change directory (again, on the originating server) to 'upload' then run an ls on it.

I suspect what you want to do is to pass the various commands as aprameters to the earlier commands.

For example, to have the gateway server initate the sftp connection:

ssh root@mrp-gateway 'sftp -v msgGoogle@126.132.45.123'

Should negate the need to issue the cd statement after connecting.