Script connecting to SFTP server

hi,

i have to type a script that connect to a server SFTP(password not required) and run some easy command (e.g. ls,rm,mv,etc...).

I wrote into the script the connection-string and the other commands.

When I run it, it connects perfectly to the server but it stops at the home.
Here is what it prints me:

AND IT DOES NOTHING!
when i write "exit" or "bye" it runs all the rest of commands (ls,mv...).

how can i do a script that connect and runs commands without asking me anything

thx a lot

You haven't been searching on this forum first have you...

look here and tell us you you did wrong:
SSH Frequently Asked Questions

I'm really sorry but i cannot understand what have I to put after "sftp -b" the -help on the shell tells that it's the "batchfile" but i really can't understand it

Well simply that your script opens a remote shell (sftp) now that shell is waiting... as you have noticed and when it ends - your script continues its execution...
Now I might have misunderstood your issue but not seeing your script there is not more to say than "have you followed the previous link and looked at the example?"

thanks vbe for you answer but i solve this way:

sorry for italian language in the script; the problem is that both the variables are empties I don't know why...

Try using expect...
It will solve all your issues

i solved the variables problem but how do you use "expect"?

It will create bigger security problems than you ever had in the first place.

Meant to add more explanation onto this but got sidetracked... expect is a third-party language/utility that can use a virtual terminal to get around hardcoded terminal requirements, allowing it to "type" into password prompts and such. But keep in mind that it's intentionally difficult to make a program type in a password prompt because they're designed that way. If your computer has your password on-hand somewhere to type in for you, that's a security nightmare.