k i
k i

Reputation: 3

In FTP command mode, how do I redirect command line and the result when using shell script using here document to let ftp command read stdin

I am trying to write shell script that implements FTP command reading here documents.

How do I redirect ftp command line AND results FTP server returns?

My current script is below

#!/bin/bash
ftp -ivn <<EOF |& tee ftplog.text
open <myFtpserver>
user <username> <password>
pwd
ls -l MYFILE_*
bye
EOF

This code outputs ftp server's response but ftp command to ftplog.txt. How can I redirect both?

I appreciate your help

Upvotes: 0

Views: 376

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7225

You should create your script on this way:

#!/bin/bash
ftp -ivn >ftplog.text  <<EOF 
open <myFtpserver>
user <username> <password>
pwd
ls -l MYFILE_*
bye
EOF

The redirection is to the command, not inline block

Upvotes: 1

Related Questions