Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do it with get instead of mget 1

Status
Not open for further replies.

josebravo

Programmer
Jun 29, 2001
7
DE
I would like to make a script which for each file of the directory, put the name of the file in a variable and then get variable. I can not use mget * because I will only need newer files and I have to know the name of the file. I wish you can help me. Thanks a lot. Jose.

for each file of the directory
{
1.- $1 = name of the file
2.- get $1
}
 
I wonder why I have problems with get command if I write

for file in 'ls'
do
get $file
done

The error message is: We only support non-print format, sorry.
?Invalid command
(remote-file) (local-file) usage: get remote-file [ local-file ]
 
Hi,

if you just have the local filenames, you don't know wether there is a newer file remote or not !?

Have you considered using "rsync" instead?

mbr
 
Oh, thanks a lot for your recommendation, but it was only an example, for knowing whether is a newer file I will us the newer command.

newer file-name
Get the file only if the modification time of the remote file is
more recent that the file on the current system. If the file
does not exist on the current system, the remote file is
considered newer. Otherwise, this command is identical to get.

But what I only need is put the name of the file in a variable and then get variable the program will be something like that:

# !/usr/bin/ksh

# set variables

export ND_ADDRESS=13x.14x.3x.xx
export ND_BASE_DIR=~/prxxx
export RICH_BASE_DIR=~/pruexxx
export ND_USER=jbxxxx
export ND_PASSWORD=gxxxx

ftp -nvi $ND_ADDRESS << quit
user $ND_USER $ND_PASSWORD
cd $RICH_BASE_DIR
lcd $ND_BASE_DIR

for i in 'ls'
do
{
newer $i
}
done

bye

The error message is: We only support non-print format, sorry.
?Invalid command
(remote-file) (local-file) usage: newer remote-file [ local-file ]

The same with get command. Thanks. Jose.

 
What you're trying to do here is use a shell loop within ftp, and that's why you're getting the error. What you could do is use the shell script to dynamically build a temporary ftp script, and then run that from the shell script. Something along these lines.
Code:
#!/usr/bin/ksh

# set variables

export ND_ADDRESS=13x.14x.3x.xx
export ND_BASE_DIR=~/prxxx
export RICH_BASE_DIR=~/pruexxx
export ND_USER=jbxxxx
export ND_PASSWORD=gxxxx
export FTP_SCRIPT=ftp_script.tmp

echo &quot;open $ND_ADDRESS&quot; > $FTP_SCRIPT
echo &quot;user $ND_USER $ND_PASSWORD&quot; >> $FTP_SCRIPT
echo &quot;cd $RICH_BASE_DIR&quot; >> $FTP_SCRIPT
echo &quot;lcd $ND_BASE_DIR&quot; >> $FTP_SCRIPT

for i in `ls`
do
{
  echo &quot;newer $i&quot; >> $FTP_SCRIPT
}
done

ftp -nvi < $FTP_SCRIPT

This may work as is, or may require some work. One point for you to note though is the &quot;quote&quot; characters around the for i in `ls` line. It's the symbol on the key above the TAB key, not a single quote.

HTH.

Greg.
 
You may want to ignore that previous post, because I think you need a list of files from the remote directory? not the local one! If that's the case, then you could do something like this ...
Code:
#!/usr/bin/ksh

# set variables

export ND_ADDRESS=13x.14x.3x.xx
export ND_BASE_DIR=~/prxxx
export RICH_BASE_DIR=~/pruexxx
export ND_USER=jbxxxx
export ND_PASSWORD=gxxxx
export FTP_SCRIPT=ftp_script.tmp

echo &quot;open $ND_ADDRESS&quot; > $FTP_SCRIPT
echo &quot;user $ND_USER $ND_PASSWORD&quot; >> $FTP_SCRIPT
echo &quot;cd $RICH_BASE_DIR&quot; >> $FTP_SCRIPT
echo &quot;lcd $ND_BASE_DIR&quot; >> $FTP_SCRIPT

# this for loop will loop through the output of the ls
# command in the remote directory $RICH_BASE_DIR.  The
# carriage returns ARE important

for i in `echo &quot;open $ND_ADDRESS
user $ND_USER $ND_PASSWORD
cd $RICH_BASE_DIR
lcd $ND_BASE_DIR
ls
bye&quot; | ftp -n`
do
{
  echo &quot;newer $i&quot; >> $FTP_SCRIPT
}
done

ftp -nvi < $FTP_SCRIPT
Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top