Home > Archive > Tcl > April 2007 > sftp over telnet using Expect
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
sftp over telnet using Expect
|
|
|
| Hi,
I am new to Expect. I am trying to write a script which will connect
to a remote machine. Then spwan sftp from the script to local machine.
Now the script will 'get' a file from
local to remote machine. I am having problem getting the file using
sftp. It shows that " Fetching the file..". But nothing is being
fetched. Can someone point out where is the in my script or how it may
work?
Script:
#!/usr/bin/expect -f
set name [lrange $argv 0 0]
set user [lrange $argv 1 1]
#spawn ssh -l $user $name
spawn telnet $name
# Look for passwod prompt
expect "linux login:"
send "$user\r"
expect "*?assword:*"
# Send password
send -- "$Password\r"
expect "~>"
send -- "\r"
spawn sftp xxx.xxx.x.xxx
expect "Password:"
send "xxxxxxx\r"
expect "sftp>"
send "get /somedir/somefile\r"
expect "sftp>"
send "bye\r"
expect "Goodbye."
send "logout\r"
Thanks.
Bani
| |
| Why Tea 2007-04-19, 4:16 am |
| On Apr 19, 1:11 am, Bani <bbane...@yahoo.com> wrote:
> Hi,
> I am new to Expect. I am trying to write a script which will connect
> to a remote machine. Then spwan sftp from the script to local machine.
> Now the script will 'get' a file from
> local to remote machine. I am having problem getting the file using
> sftp. It shows that " Fetching the file..". But nothing is being
> fetched. Can someone point out where is the in my script or how it may
> work?
> Script:
> #!/usr/bin/expect -f
> set name [lrange $argv 0 0]
> set user [lrange $argv 1 1]
> #spawn ssh -l $user $name
> spawn telnet $name
> # Look for passwod prompt
> expect "linux login:"
> send "$user\r"
> expect "*?assword:*"
> # Send password
> send -- "$Password\r"
> expect "~>"
> send -- "\r"
> spawn sftp xxx.xxx.x.xxx
Looks like this is the problem as you should really do:
exp_send "sftp xxx.xxx.x.xxx"
I assume this is what you tried to do:
telnet sftp
a----------->b----------->c
And, you ran expect on a.
| |
| Why Tea 2007-04-20, 4:14 am |
| On Apr 19, 8:11 pm, Bani <bbane...@yahoo.com> wrote:
> On Apr 19, 2:13 am, Why Tea <ytl...@gmail.com> wrote:
>
>
>
>
>
>
>
>
> Hi Tea,
> Thanks for the response.
>
> I tried to do
> telnet sftp
> a--------->b---------->a (the local machine) and yes I ran expect on
> a.
>
> Bani
That looks strange.
>From your diagram, you telnet from a to b and then sftp from b back to
a. Wouldn't it be the same by simply sftp from a to b? Or perhaps I
have misunderstood you?
In any case, your script doesn't do as you want. This is what really
is happening:
a-------------------------->b
telnet
sftp
Expect opens two channels on a towards b, not as you intended. As I
stated earlier, you should use "exp_send sftp..." once you are
connected to b.
| |
| Bezoar 2007-04-20, 7:07 pm |
| On Apr 20, 2:41 am, Why Tea <ytl...@gmail.com> wrote:
> On Apr 19, 8:11 pm, Bani <bbane...@yahoo.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
> That looks strange.
>
>
> a. Wouldn't it be the same by simply sftp from a to b? Or perhaps I
> have misunderstood you?
>
> In any case, your script doesn't do as you want. This is what really
> is happening:
>
> a-------------------------->b
> telnet
> sftp
> Expect opens two channels on a towards b, not as you intended. As I
> stated earlier, you should use "exp_send sftp..." once you are
> connected to b.
what he says is correct you need to change your spawn to
a simple send so :
.....
expect "~>"
send -- "\r"
spawn sftp xxx.xxx.x.xxx
expect "Password:"
send "xxxxxxx\r"
.....
becomes
.....
expect "~>"
send -- "\r"
send "sftp xxx.xxx.x.xxx\r"
expect "assword:"
send "xxxxxxx\r"
.....
Carl
| |
|
|
>
>
>
>
> That looks strange.
>
>
> a. Wouldn't it be the same by simplysftpfrom a to b? Or perhaps I
> have misunderstood you?
>
> In any case, your script doesn't do as you want. This is what really
> is happening:
>
> a-------------------------->b
> telnet
> sftp
> Expect opens two channels on a towards b, not as you intended. As I
> stated earlier, you should use "exp_sendsftp..." once you are
> connected to b.
Sorry, for late response(I was way from my computer)!
You are correct, I can simply do sftp from a to b, actually the remote
machine, b, is not allowing me to do sftp from a. I should mention
this in my posting.
I need to transfer file from a to b and compute checksum of
transmitted and local file. So, I thought of doing this way.
I understood from your explanation where my script is wrong.
I will use "exp_sendsftp... and see how it goes.
Thanks a lot.
| |
|
| On Apr 20, 9:03 am, Bezoar <cwjo...@gmail.com> wrote:
> On Apr 20, 2:41 am, Why Tea <ytl...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> what he says is correct you need to change your spawn to
> a simple send so :
> ....
> expect "~>"
> send -- "\r"
> spawnsftpxxx.xxx.x.xxx
> expect "Password:"
> send "xxxxxxx\r"
> ....
>
> becomes
> ....
> expect "~>"
> send -- "\r"
> send "sftpxxx.xxx.x.xxx\r"
> expect "assword:"
> send "xxxxxxx\r"
> ....
>
> Carl
Thanks. I will do that.
| |
|
| On Apr 23, 1:52 pm, Bani <bbane...@yahoo.com> wrote:
>
>
>
>
>
>
>
>
> Sorry, for late response(I was way from my computer)!
>
> You are correct, I can simply dosftpfrom a to b, actually the remote
> machine, b, is not allowing me to dosftpfrom a. I should mention
> this in my posting.
> I need to transfer file from a to b and compute checksum of
> transmitted and local file. So, I thought of doing this way.
> I understood from your explanation where my script is wrong.
> I will use "exp_sendsftp... and see how it goes.
> Thanks a lot.
With ' send "exp_sendsftp....", the script worked! Thanks, Tea, Carl .
|
|
|
|
|