FTP script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

FTP script

Shell Programming and Scripting


Tags
automated login, ftp

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-18-2003
jfieck jfieck is offline
Registered User
 
Join Date: Nov 2003
Last Activity: 18 November 2003, 5:10 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
FTP script

I am trying to write a script that will ftp a file to a remote server then end the ftp connection to that server when the file has been transfered.

The problem is when I use the line "ftp 10.0.0.1" in the script. Then ftp wants a username and password. How can I hard code the user name and password in the script and set the script up to enter it automtically.

I also need to use the script to end the ftp session but when the ftp command is called the control moves to the remote computer.

If anyone has any suggestions on how to use a script to create an ftp session, push a file, then end the session one the file is pushed please do tell.
Sponsored Links
    #2  
Old 11-18-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
 
Join Date: May 2001
Last Activity: 24 March 2008, 9:43 PM EDT
Location: Chicago IL, USA
Posts: 1,006
Thanks: 0
Thanked 2 Times in 1 Post
this questions has been answered many times. Please use the search utility on this site.
Sponsored Links
    #3  
Old 11-18-2003
jfieck jfieck is offline
Registered User
 
Join Date: Nov 2003
Last Activity: 18 November 2003, 5:10 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
My applogies. I'm new to this list. Thanks for the reply.
    #4  
Old 12-04-2003
CarlosManjarres CarlosManjarres is offline
Registered User
 
Join Date: Dec 2003
Last Activity: 4 December 2003, 4:38 PM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Perhaps you are asking for a script to trasnfer a file using FTP to an FTP server (local or remote).

If so, I would create 2 files:

1) .ftp_put.cfg
2) ftp_trasnsfer.ksh script

Note that I have removed the login parameters from the script.
This way you can modify the login parameter to point to any server without modifying the actual ftp script.

.ftp_put.cfg
-----------------------
FTP_HOST=your.host.com
FTP_LOGIN=your_account
FTP_PASSWORD=your_password

ftp_transfer.ksh
-----------------------
#!/bin/ksh

localFile=$1
remoteFile=$2

#source FTP parameters
. .ftp_put.cfg

mylog=ftp_session.log
echo "$(date "+%H:%M:%S") - Attempt to FTP $1 to $2" > $mylog

# do the FTP put

ftp -i -n <<EOF >> $mylog
open $FTP_HOST
user $FTP_LOGIN $FTP_PASSWORD
put $localFile $remoteFile
ls $remoteFile
quit
EOF


Warning!! This script does not have any transfer verification logic.


usage sample:

ftp_transfer.ksh readme.txt /pub/dir1/readme.txt
Sponsored Links
    #5  
Old 02-19-2008
prasanth_babu prasanth_babu is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 7 October 2013, 6:59 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Dear,

I have come up with the same in different logic.the details of the same mentioned below;

1.Execute_FTP.sh : Main Script which will carry out the functionality of FTP.
2.Parser.sh :IP USERNAME PASSWORD SOURCE FILENAME
3.Upload.sh : FTP Environment Commands .


Execute_FTP.sh

./Parser.sh 10.132.207.2 onm onm /home/smvdba/Prasanth/OUT DiskAlert.txt /tmp/Alert/VDS

Parser.sh

set -x

if [ $# != 6 ]; then
echo "Usage
./Parser.sh IP USERNAME PASSWORD SOURCE FILENAME DESTINATION
where
IP ------------- IP address of remote server
USERNAME-------- username with which to establish ftp session
PASSWORD-------- password for the above mentioned USERNAME
SOURCE --------- source directory
FILENAME ------- name of the file to be ftped
DESTINATION----- path at remote directory at which file is to be kept"
exit
fi

HOME=/home/smvdba/Prasanth/OUT
DIRECTORY=$4
LOG=$HOME/LOG
EXPECTED_RETURN="221 Goodbye."
LIST_OF_FILES=list_of_files
cd $DIRECTORY
ls -lrt $5* >$LIST_OF_FILES

cat $LIST_OF_FILES|while read LINE
do
filename=`echo $LINE|awk '{print $9}'`
size=`echo $LINE|awk '{print $5}'`
if [ "$filename" = "" ]; then
filename=temp

elif [ "$filename" = "_" ]; then
filename=temp

else
echo "Transfering $filename"
sh $HOME/upload.sh $filename $1 $2 $3 $6 >$LOG/ftp_log
RETURN=`fgrep "221 Goodbye." $LOG/ftp_log`

if [ "$RETURN" = "${EXPECTED_RETURN}" ]

then
mv $DIRECTORY/$filename $DIRECTORY/FTPED/$filename
else
echo "Unable to establish connection"
fi

fi
done

Upload.sh


FILE=$1
IP=$2
USER=$3
PASS=$4
DESTINATION=$5
#cd OUTPUT/CIRCLE2
ftp -inv $IP<< !EOF
user $USER $PASS
cd $DESTINATION
prompt
asc
put $FILE Temp_$FILE
rename Temp_$FILE $FILE
quit
!EOF


Best Regards!
Prasanth Babu.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with shell script - Calling a script through script Siddheshk Shell Programming and Scripting 0 04-18-2011 05:14 AM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 02:50 AM



All times are GMT -4. The time now is 02:41 AM.