Operating System - HP-UX
1754914 Members
3916 Online
108827 Solutions
New Discussion юеВ

ftp script variable file list

 
SOLVED
Go to solution
Paul Gerke
Advisor

ftp script variable file list

How can I define a dynamic list of file to be ftp'd within a script? I tried the following:

FLIST=`ls 60*`
ftp <<-@EOF
prompt off
mput $FLIST
bye
@EOF

Thanks
Rich
Paul
5 REPLIES 5
Bill Hassell
Honored Contributor
Solution

Re: ftp script variable file list

Almost but not quite. The ls * is a local Unix command. Remember that ftp can go to any machine, mainframes to Macs to PCs to whatever and the remote machine won't understand Unix shelll scripting.

However, mput does understand file name meta-characters (called globbing). From the ftp man page:

When file name globbing is enabled, ftp expands csh(1) metacharacters in file an
d directory names. These characters are *, ?, [, ], ~, {, and }.

The server host expands remote file and directory names. Globbing metacharacters are always expanded for the ls and dir commands. If globbing is enabled, metacharacters are also expanded for the multiple-file commands mdelete, mdir, mget, mls, and mput.

So just put mget * in your script. Since the script will expand shell script masking characters, be sure to escape the * with a backslash.


Bill Hassell, sysadmin
Erkan Durmus
Advisor

Re: ftp script variable file list

Dear Rich,
Firstly you should use ftp with -i option, so it will not ask you to copy a file if you use mget, mput options which are described by Bill. If you want to use mput you may put the files to be transferred to a directory and use that directory in your script like mput $DIR/*.
Another option is to create ftp sctipt by another script and run this newly created script.

Regards,
Erkan Durmus
Unix is always UNIX
Erkan Durmus
Advisor

Re: ftp script variable file list

Dear Rich,
Firstly you should use ftp with -i option, so it will not ask you to copy a file if you use mget, mput options which are described by Bill. If you want to use mput you may put the files to be transferred to a directory and use that directory in your script like mput $DIR/*.
Another option is to create ftp sctipt by another script and run this newly created script.

Regards,
Erkan Durmus
Unix is always UNIX
Erkan Durmus
Advisor

Re: ftp script variable file list

Dear Rich,
Firstly you should use ftp with -i option, so it will not ask you to copy a file if you use mget, mput options which are described by Bill. If you want to use mput you may put the files to be transferred to a directory and use that directory in your script like mput $DIR/*.
Another option is to create ftp sctipt by another script and run this newly created script.

Regards,
Erkan Durmus
Unix is always UNIX
Paul Gerke
Advisor

Re: ftp script variable file list

Sorry I took so long to get back to this. The help from both of you was much appreciated.
Paul