Auto FTP to a server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto FTP to a server
# 8  
Old 03-22-2006
Hi,

It sounds great that you found the solution.Actually this script is for multiple file transfer we can ftp single file too..and it support metacharecters in filename like file* will transfer all files starting with file.After completion of script log file will be generated and those file names transferred and could not transferred will be displayed on prompt.
# 9  
Old 03-22-2006
Where is the script ??? Smilie
# 10  
Old 03-22-2006
here i am sharing my script

#script name: mfileftp.sh
#purpose: Script File for Multiple Files FTP Program which support *and ? metachars
#Details: This script generates one log file which contains server output and custom output as names of files ftp to server
# and contain warning message which says which files could not transferred
# log file will be created in the source directory with name ftp_log_ddmmyyhhmn.log
#USAGE: sh mfileftp.sh ftpserver username pwwd d/sourcedirectory d/destinationdir file1...file2...file*
# use d as command line parameter for default otherwise put directory
#prerequisite: user must have write permission in the source directory
#Author:
#version: 1.6


v_source_ip=$1
v_user_id=$2
v_pwd=$3
v_source_dir=/usr/sdir #put some directory for default usage
v_dest_dir=/usr/ddir #put some directory for default usage
#this temp file will remain in existance to run commands on ftp prompt, will be deleted at the end of script.

temp=$v_source_dir/temp_ftp.tmp
underscore_char=_

TIMESTAMP=`date +%d%m%y%H%M`
log=$v_source_dir/ftp_log$underscore_char$TIMESTAMP.log


if [ $# -lt 6 ]
then
echo "Improper Usage:$0"
exit
fi


if [ $# -eq 5 ]
then
echo "improper usage:File name missing"
fi


#Remove temp file if exist

if [ -f $temp ]
then
rm $temp
fi

#Remove log file if exist
if [-f $log ]
then
rm -f $log
fi



#Check if file name is given and validate source and destination directory

if [ $# -gt 5 ]
then
if [ $4 = "d" ]
then
echo " Default Source Dir Used : $v_source_dir"
elif [ -d $4 ]
then
v_source_dir=$4
else
echo "Invalid Source directory or Improper Usage"
exit
fi
# check for destination dir

if [ $5 = "d" ]
then
echo " Default Destination Dir Used : $v_source_dir"
else
v_dest_dir=$5
fi



#Creation of temp file from where all the commands will be executed
#changing mode of file so no one else can see it

touch $temp
chmod 700 $temp
#c=`ls -l $temp`
#echo "$c"
echo "user $v_user_id $v_pwd" > $temp
echo "cd $v_dest_dir" >> $temp
echo "lcd $v_source_dir" >> $temp
echo "binary" >> $temp
#echo "hash" >>$temp


#shift first 5 parameters to get files passed in command line
#in loop we check if file exist then we put in command file else we put in error file change ver 1.6

shift 5
while [ $# -gt 0 ];
do
if [ -f $1 ]
then
echo "mput $1" >> $temp

else
echo "file::\" $1 \" do not exist" >>$v_source_dir/ftp_error.err #this file will not be created if all files passed are valid
fi
shift 1
done
echo "bye" >> $temp

#the following command will open ftp session and and run commands from $temp file
#each command will put its message to the $log file as we have redirected output to the file in place of terminal

ftp -nvi $v_source_ip < $temp >$log


#Now we will append our custom message to the log file which will show the names of files transferred during the run
#with grep command we will take those lines contains filenames and put in temp_fill file
#As filenames are second field in the temp_fill file we cut those fields and append it to $log file

echo "\n\n"
echo "Files Transfered in this run...." >>$log
grep "local:" $log>$v_source_dir/temp_fill
cut -f 2 -d" " $v_source_dir/temp_fill>>$log

if [ -f $v_source_dir/ftp_error.err ] #check if err file contains some info then append it to log file ver 1.6
then
echo "\nWarning:\n">>$log #change ver 1.6
cat $v_source_dir/ftp_error.err>>$log #append error message to log file(change ver 1.6)
fi

#following command will display contents of temp file, name of files FTPed to remote machine(change ver 1.6)
echo "files transfered in this run"
cat $v_source_dir/temp_fill
echo "\n"
if [ -f $v_source_dir/ftp_error.err ]
then
echo "\nWarning:\n"
cat $v_source_dir/ftp_error.err #change ver 1.6
fi

fi #end of outer if which checks for no of parameters are greater than five

#remove temp_fill and temp file for security

rm -f $v_source_dir/ftp_error.err #change ver 1.6
rm -f $v_source_dir/temp_fill
rm -f $temp
echo "For more detailed log information please see log file::$log" #change ver 1.6
echo "Automated FTP script completed..."
# 11  
Old 03-22-2006
thanks a lot for sharing Smilie
# 12  
Old 03-22-2006
try this

#!/bin/sh

if [ "$#" -lt 4 ]
then
echo "Usage: ./ftp_script <M/C Name> <Userid> <Password> <Path>"
exit
fi

ftp -idn << !
open $1
user $2 $3
close
bye
!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Implement FTP server on RHEL server without using FTP client

We have RHEL 5.8 in our environment, I had a query whether we can implement an FTP server using vsftpd package and Linux configurations like setsebool without using any external FTP clients like FileZilla etc. I am very confused on this. The FTP functionalities that should be present are download &... (3 Replies)
Discussion started by: RHCE
3 Replies

2. Shell Programming and Scripting

[Need HELP] Find aging file and auto FTP

Dear Experts, I have script to find aging file like this: find /ArchiveINTF/INTF name "*" -type f -mtime +365 {} \; >> agingfile.txt This script will find all files over 365 days. But, I have problem, how to auto FTP all files? Thanks Edy (3 Replies)
Discussion started by: edydsuranta
3 Replies

3. Homework & Coursework Questions

How to auto telnet the server from another server?

Hi All, I have a problem with auto telnet script, but I want to tell u something a) I am only a member access on the server, so not able to access 'root' account b) not able to install any software on server 3) On server, there is not install 'except' 1. The problem statement, all variables... (8 Replies)
Discussion started by: atul9806
8 Replies

4. Homework & Coursework Questions

How to auto telnet the server from another server

Hi All, I have a problem with auto telnet script, but I want to tell u something a) I am only a member access on the server, so not able to access 'root' account b) not able to install any software on server 3) On server, there is not install 'except' 1. The problem statement, all variables... (0 Replies)
Discussion started by: atul9806
0 Replies

5. Shell Programming and Scripting

How to auto telnet the server from another server using script

Hi All, I have a problem with auto telnet script, but I want to tell u something a) I am only a member access on the server, so not able to access 'root' account b) not able to install any software on server 3) On server, there is not install 'except' I have to write a script, which is ran... (0 Replies)
Discussion started by: atul9806
0 Replies

6. Shell Programming and Scripting

Auto Ftp pseudo random file

I have a script that generates a file which is my own incarnation of a date using the 'date' function (we'll call this script a). I would like that script to invoke my other script (script b) which contains my ftp info. Since I have yet to figure out a good way to use regular ftp (yes i can only... (6 Replies)
Discussion started by: DC Slick
6 Replies

7. Solaris

Sun Server auto ping to 0.0.0.0

Hi All, 3 of my SAP sun server are continuosly pinging to the network address 0.0.0.0. I have no idea how this can happen, but they have something in common. All of them are clustered environment (Veritas Cluster). Anyone can help? rgds, (5 Replies)
Discussion started by: ronny_nch
5 Replies

8. UNIX for Advanced & Expert Users

Count and Auto FTP

Hi, I really need to create a script that counts for file and ftp's them to a windows directory. !st problem i'm having is getting it to ftp withouty prompting me, i tried |& on the end of the ftp, but then it just hits a syntax error. 2nd problem is, i have to have a wildcard in this script. which... (3 Replies)
Discussion started by: dappa
3 Replies

9. Shell Programming and Scripting

auto ftp the files

i have writen a shell to ftp a file automatically by taking the input from a file i have created on file tstftp as set timeout 120 ftp spawn ftp expect "ftp>" send "o 11.90.2.20 \r" expect "Name:" send "itcomxxl\r" expect "Password:" send "csms091206\r" expect "ftp>" send "prompt... (1 Reply)
Discussion started by: sasiprabu
1 Replies

10. Programming

Auto FTP from UNIX to Windows Server

Hi, I am a not strong programmer and now my boss ask me how should I do a job to automated FTP that have error check. I know about: * using system() to call a command to trigger ftp in C Coding. The senarios as follows: 1. FTP the file(s) (e.g ELA_20060407.dat) to a given LAN server... (1 Reply)
Discussion started by: songtam
1 Replies
Login or Register to Ask a Question