Operating System - Tru64 Unix
1754811 Members
3577 Online
108825 Solutions
New Discussion юеВ

Re: Script for FTPing files to another server

 
k_75
Occasional Advisor

Script for FTPing files to another server

Hi to all,

I wish to write a script in TRU64 (5.1) for following purpose:

1. To ftp some critical ascii & binary files from production server to DR server on daily basis.
2. Change ownership(chown) and permissions (chmod) of files thus transferred to DR server.

I have following concerns/requirements:
1. If possible, I wish to run it in background. Whenever this file is created in Prod server, it should be able to detect it and initiate a ftp to DR server.
2. I do not wish to embed any password (if required) into the script.

Can anyone provide any suggestion, pointers, source of TRU64 scripting reference books that can help me out with the above?
Any help will be appreciated.

Regards.
9 REPLIES 9
Steven Schweda
Honored Contributor

Re: Script for FTPing files to another server

Normal FTP is typically anonymous (where no
one cares about the password), or else it
uses a real user name and password, in which
case you would need, but don't really want,
the password in your script. As you're
_sending_ files, anonymous FTP is a poor
choice, and if you're trying to keep the
password hidden, normal FTP is not much
better.

Assuming that something like NFS is not
available, you could use a scheme like
"sftp" or "scp", which use the same
authentication schemes as "ssh", including
host-based and public key. This would
obviate the inclusion of the password in your
script.

"man sftp" suggests that chown and chmod
are not available within sftp, but you could
use separate "ssh" commands after the sftp
transfers are complete.

You can use "cron" to run the script
periodically, and it could check the source
directory ("ls" or, perhaps, "find") to see
if there are any files to be sent.

There must be a zillion scripts like this
which have already been written, but I don't
have one.
Steven Schweda
Honored Contributor

Re: Script for FTPing files to another server

And if both ends are UNIX (or UNIX-like),
then the ASCII-binary distinction is not
important.
Ivan Ferreira
Honored Contributor

Re: Script for FTPing files to another server

For ftp, you can use something like this:

echo "user username password
asc
cd $FTPDIR
lcd $LOCALDIR
mput *
site chmod *
bye" | ftp -i -n ftp.personal.com.py


If you don't want to specify the password in the script, you must use scp with public keys authentication. Your public key must be generated without a passphrase. See man ssh-pubkeymgr.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
k_75
Occasional Advisor

Re: Script for FTPing files to another server

Thanks folks.
Can you also provide pointer to some scripting reference material that I can refer to?
Orjan Petersson
Frequent Advisor

Re: Script for FTPing files to another server

I would not recommend Ivan's solution as there is no way to handle failures that way.

A better way is to control the ftp client from expect (http://expect.nist.gov/) or use a scriptable ftp client, such as kermit (http://www.columbia.edu/kermit/index.html, http://www.columbia.edu/kermit/ftpclient.html).

Note that Kermit can also be used for secure ftp connections, see http://www.columbia.edu/kermit/ckermi80.html#x3.2
Steven Schweda
Honored Contributor

Re: Script for FTPing files to another server

As someone has probably done this before, you
might try asking Google about something like:

"shell script" ftp

One thing it turned up, for example, was a
pretty complete Kermit solution:

http://www.columbia.edu/kermit/ftpscripts.html
Harmanjit_1
Frequent Advisor

Re: Script for FTPing files to another server

If you don't want to put password in script, you can use sftp, generate the public keys and put in remote host for doing it without passwd
Steven Schweda
Honored Contributor

Re: Script for FTPing files to another server

> [...] you can use sftp, [...]

[Forehead smack!] Doh! Why didn't I think
of that, and suggest it two days ago?!!

No, wait. I did. Never mind.
Mario Stargard
Advisor

Re: Script for FTPing files to another server

rsync is ideal for this task, plus it can use either rsh or ssh as the transport. What's neat about rsync is that it only copies the files that have changed. rsync has the capability to preserve (or not) permissions and ownership.

You'll need to build it from source and put a symlink to it in /usr/bin/rsync.

Mario