Operating System - HP-UX
1826372 Members
3623 Online
109692 Solutions
New Discussion

Re: Using FTP commands in a Script & Running in Cron

 
SOLVED
Go to solution
Garrin Thompson
Advisor

Using FTP commands in a Script & Running in Cron

I have SAMBA installed and understand how to use it well, however, we'd prefer to use FTP to put a very large file onto an NT Server that is on the same network. I am familiar with FTP commands, but have been unable to assertain how to use FTP in a script and to connect to the NT server. Really, these are 2 issues...Scripting FTP commands, and connecting to the NT Server. Ultimately, we'll put this script in cron to run unattended at night.

Can anyone with experience in this help me learn?

Your help is greatly appreciated.
2 Years old on HP-UX 10.20 R9000 server
5 REPLIES 5
Rick Garland
Honored Contributor

Re: Using FTP commands in a Script & Running in Cron

Can you connect to the NT server via FTP? I believe that certain software is required.
With that being said, here is a short a simple FTP script I use:

ftp -n -v >> $LOG <user
(get, put etc...)
quit

There are numerous past threads discussing the same issue.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Using FTP commands in a Script & Running in Cron

Garrin:

There have been a wealth of comments and examples in this forum recently on this topic. Do a search for FTP within this formum. I think you will find what you are seeking.

...JRF...
Stefan Farrelly
Honored Contributor

Re: Using FTP commands in a Script & Running in Cron


The simplest way to put it in a script is to create a $HOME/.netrc file with the details on the server you want to connect to so you can log in automatically;
eg. machine login password

Then you can easily call ftp in a script by doing;

ftp <cd
send or get
quit
EOF

Thats all you need.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Bill Hassell
Honored Contributor

Re: Using FTP commands in a Script & Running in Cron

The key is to use ftp -n. Here's a quick example which uses the standard shell script technique called a 'here document':

#!/usr/bin/sh
#
# usage:
#
# batchftp.sh remote-host user-ID pw source-file destination-directory
#
if [ $# -ne 5 ]
then
echo
echo "Usage: $0 remote-host user-ID pw source-file destination-directory"
echo
exit 1
fi

ftp -n << EOF
open $1
user $2 $3
put $4 $5
EOF


It is a general example...you can certainly customize it. The nice part of a shell here document is that environment variables outside the ftp program can be passed to the commands. FTP is also the most efficient method of file transfer and is also quite portable. It has code to translate the myriad of ASCII file formats between different operating systems (ie, DOS vs HP-UX). FTP will adjust the transmission and acknowledgement windows based on the speed of the transmission medium.


Bill Hassell, sysadmin
Garrin Thompson
Advisor

Re: Using FTP commands in a Script & Running in Cron

Thanks everyone. I took the advice to search and found out a lot of things to help me along with the information that you all wrote.

For starters, we didn't want to use SAMBA because it is slow for us, but I learned from other threads on FTP that SAMBA may be slow if you use NetBios name resolution instead of the IP of the server. Knowing that, I tested the use of SAMBA and it now puts at the same speed of normal FTPing.

I also learned of a product called Sharity (http://www.obdev.at/Products/Sharity.html) that treats NT Server shares as mount points on my HP-UX box. This is the answer to our needs. We can have our MF Cobol programs write directly to the server now and don't have to worry about FTPing or using SAMBA. This takes out at least 2 steps.

Thank you all and I hope what I learned helps you someday as you've helped me.
2 Years old on HP-UX 10.20 R9000 server