1825804 Members
2520 Online
109687 Solutions
New Discussion

Re: Automated FTP - help

 
SOLVED
Go to solution
Jagadesh_2
Regular Advisor

Automated FTP - help

Hi Admins,

I have a requirement to schedule an automated ftp from UNIX server to WINDOWS server. Only the files which are created today needs to be pushed to the windows server (ie: according to the timestamp).

Not sure as how this can be implemented in a script. I was aware that automated FTP can be done by creating a .netrc file under the home directory.

Thanks in advance
S.Jagadesh
8 REPLIES 8
Andy Torres
Trusted Contributor

Re: Automated FTP - help

A. Clay Stephenson
Acclaimed Contributor

Re: Automated FTP - help

This does assume that your Windows box has a running telnet daemon (okay in Windows speak a service) but the simplest method (that also does full error checking) is to use Perl's Net::FTP module. The attached Perl script will do everything you need.

ftpput.pl -h remotehost -l cstephen -p topsecret -A -d /xxx/yyy myfile1 myfile2
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Transfer ok"
else
echo "Transfer failed; status ${STAT}" >&2
fi

This will login to remotehost as user cstephen, password topsecret, cd to /xxx/yyy, set ASCII mode (-A; -B = binary); and then put myfile1 and myfile2.

Invoke as ftpput.pl -u for full usage. If a .netrc file is found the password argument is not needed.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Automated FTP - help

If an FTP service is not running on the Windows box, you can turn the problem around and let the Windows box do a get with ftpget.pl. You will need to install one of the free Perl's for Windows (www.activestate.com) but the good news is that either of these scripts works requally well on UNIX or Windows. Now do that with a shell script or a stupid .BAT file.

Invoke as ftpget.pl -u for full usage.
If it ain't broke, I can fix that.
Jagadesh_2
Regular Advisor

Re: Automated FTP - help

Stephen / Andy,

Thanks for your valuable sugessions.
I am much worried about the time stamp. As i need to ftp the files (created on daily basis only) from unix to windows server.
A. Clay Stephenson
Acclaimed Contributor

Re: Automated FTP - help

The transferred file will be timestamped as of the time the transfer was completed. This is a copy of a file and anything else would be false. There are utilities (e.g. touch) that will allow you to change these timestamps but that is up to you.
If it ain't broke, I can fix that.
Muthukumar_5
Honored Contributor

Re: Automated FTP - help

Several ways to achive this:

a) Using .netrc file.

Refer netrc man page

b) ftp -in <<-EOF
user
...

...
bye
EOF

c) Using expert scripting - to get security on password.

a and b methods are using password in plain text method.

--
Muthu
Easy to suggest when don't know about the problem!
Raj D.
Honored Contributor

Re: Automated FTP - help

Hi Jagadesh ,

You can check this:

###############################
#!/usr/bin/sh
DATE=`your date format` #Ex: `date +%m%d%y `
sourcefile="filename.${DATE}"
sourcedir="/filesystem/somedir//"


cd $sourcedir
ftp -n IP_ADDRESS_OF_WIN_SERVER << EOF
user USER PASSWORD
cd "C:\win2k\filesave\"
put $sourcefile
bye
EOF

##############################

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Arturo Galbiati
Esteemed Contributor
Solution

Re: Automated FTP - help

Hi,
you can use this:

#!/usr/bin/ksh
cd
touch -t $(date +%y%m%d0000) timestamp
{
echo "ftp -inv <echo "user "
echo "ascii"
for File_name in $(find . -type f -newer timestamp)
do
echo "put $File_name"
done
echo "quit"
echo "END_OF_FTP"
}>ftpx
./ftpx >ftp.log 2>&1
rm timestamp
rm ftpx


instead of , , use appropriate value.
This script will create another script ftpx whcih will contain all teh comamnd to ftp file created today.

HTH,
Art