I’m using the ftp command line tool and want combine scripted input with user input. With only user input the prompt looks like this:


But when I try to insert some input with a script, like

{echo "user username passwd"; cat;} | ftp -n server.tld

How can I force ftp (or any cli) to still use the interactive mode?

I would prefer a solution based on standard shell tools.

  • 2
    I would switch to the lftp client for starters if you're attempting to do any scripting of FTP. The cli ftp is pretty weak in comparison. – slm Oct 1 '14 at 13:43

There is a program to interact with interactive command line tools exactly like the ftp example: expect. It is a specialized script shell, extending the on the scripting language tcl.

It is very powerful, but you may get away without learning everything about it. A very useful tool is autoexpect, which can record an interactive session as an expect script. The recorded script is certainly helpful to understand the basics.

A expect script can interact with an interactive program like ftp. This can be combined with interaction of the user and the interactive program. Using the command interact in an expect script, the control can be given to the user temporarily.
While the user has control, the script still listens for events to take back the control, so practically, both the user and the script are interacting simultaneously with the program.

  • Indeed it is possible to give control to the user via expects interact command. – bodo Nov 9 '14 at 13:08
  • @canaaerus yes, that's what I meant; Added some details on it. – Volker Siegel Nov 9 '14 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.