1819965 Members
3439 Online
109607 Solutions
New Discussion юеВ

ftp scripting question

 
SOLVED
Go to solution
Dennis Flinn
Advisor

ftp scripting question

I was wondering if someone might answer a question. I have written a number of ftp scripts similar to the following:

ftp -n -v << endl >> ach_ftp.log
#
# Open an ftp connection
# Pass in username and password
# Set the transfer mode binary).
# Put the file into the ftp location
# Quit the ftp connection.
# Close the log file.
#
open $NODE
user $USERID $PASSWD
binary
put $PGP_DAILY/ach.encrypted $FILE
quit
endl

However if I indent the lines for readability in the script - the script will not work. I was just wondering why the commands can't be indented in the script?

Dennis
8 REPLIES 8
baiju_3
Esteemed Contributor

Re: ftp scripting question

The comments should come fisrt and then follow the ftp commands .

Is that what you are looking for or detail how you are indenting .


# Open an ftp connection
# Pass in username and password
# Set the transfer mode binary).
# Put the file into the ftp location
# Quit the ftp connection.
# Close the log file.
#
ftp -n -v << endl >> ach_ftp.log
open $NODE
user $USERID $PASSWD
binary
put $PGP_DAILY/ach.encrypted $FILE
quit
endl

thx,
bl.
Good things Just Got better (Plz,not stolen from advertisement -:) )
James R. Ferguson
Acclaimed Contributor

Re: ftp scripting question

Hi Dennis:

The technique you are using is called a "here-document". Input is read up until the word that follows the '<<'. In this case you choose the word "endl" which cannot be indented.

If a '-' is appended to the '<<', then all leading *tab* characters are stripped from word and from the document. This *does* allow for indentation.

Regards!

...JRF...

Victor Fridyev
Honored Contributor
Solution

Re: ftp scripting question

Hi Dennis,

You can use file .netrc in homedir of the user, which run ftp. For ftp session on NODE the file must contain the following part:
machine NODE
login USER
password PASSWORD
macdef init
bin
cd incoming
lcd /tmp
put swlist.out
quit

You can modify the file from a script and after that run ftp NODE

HTH
Entities are not to be multiplied beyond necessity - RTFM
Bill Hassell
Honored Contributor

Re: ftp scripting question

As James mentioned, you can use <<- as the flag for your end-of-input string and then you can use tabs (but NOT spaces). However, you can put spaces and/or tabs in front of the ftp commands and still use just the << flag--just make sure that the end-of-input string (endl in your case) starts in column 1. Since indenting is usually done for readability, you might use ALL CAPS for your endl string: ENDL


Bill Hassell, sysadmin
Muthukumar_5
Honored Contributor

Re: ftp scripting question

Use like,

ftp -ivn $NODE <<-EOF << ach_ftp.log
use $USERID $PASSWD
binary
put $PGP_DAILY/ach.encrypted $FILE
bye
EOF

will suite to use intent requirement.

-Muthu
Easy to suggest when don't know about the problem!
Arturo Galbiati
Esteemed Contributor

Re: ftp scripting question

Hi Dennis,
you you want to indent you can use <<- and tabs.
From man ksh:
<<[-]word The shell input is read up to a line that matches
word, or to an end-of-file. No parameter
substitution, command substitution, or file name
generation is performed on word. The resulting
document, called a here-document, becomes the
standard input. If any character of word is
quoted, no interpretation is placed upon the
characters of the document. Otherwise, parameter
and command substitution occurs, \new-line is
ignored, and \ must be used to quote the
characters \, $, `, and the first character of
word. If - is appended to <<, all leading tabs
are stripped from word and from the document.

HTH,
Art
Muthukumar_5
Honored Contributor

Re: ftp scripting question

This is,

If - is appended to <<, all leading tabs
are stripped from word and from the document.


what you are requiring.

-Muthu
Easy to suggest when don't know about the problem!
Dennis Flinn
Advisor

Re: ftp scripting question

Thanks for all the responses. They were all helpful and informative.

Dennis