If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Automation Of FTP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-22-04, 09:09
meenuramesh meenuramesh is offline
Registered User
 
Join Date: Mar 2004
Posts: 5
Exclamation Automation Of FTP

How to automate an FTP session through shell script.

The ftp site name, user name, password has to be user defined during run time, not to be given in shell script.

Can anyone tell me how to do this in shell script.
Reply With Quote
  #2 (permalink)  
Old 03-22-04, 13:27
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
Re: Automation Of FTP

#Try this ----


echo "Enter ftp user name"
read FTPUSER
echo "Enter ftp user password"
read FTPPASS
echo "Enter destination server"
read FTPSERVER
echo "Enter file to transfer"
read FTPFILE
ftp -n $FTPSERVER <<END_SCRIPT
user $FTPUSER $FTPPASS
put $FTPFILE
quit
END_SCRIPT
exit 0
Reply With Quote
  #3 (permalink)  
Old 03-22-04, 13:34
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
Re: Automation Of FTP

I thought of removing the line
exit 0
before posting it here but forgot. ( Remove the line if you don't want to exit out of your user session after running the script )
Reply With Quote
  #4 (permalink)  
Old 03-27-04, 05:16
meenuramesh meenuramesh is offline
Registered User
 
Join Date: Mar 2004
Posts: 5
Exclamation Re: Automation Of FTP

Hi,

It is working fine.

I need some more clarification.

I want to connect to a ftp server and on the ftp server i want to check for the availability of a file.

How to do this in a shell script.

As per your help I am able to connect to the ftp site by getting user password & server details from user. Can I also mention the file to search in the ftp server along with these during run time.

I tried, but it is not working. Can you pls help me

Regards,
R.Ramesh.
Reply With Quote
  #5 (permalink)  
Old 03-27-04, 13:17
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi, try this

FTP_USER="guest"
FTP_PASS="guest"
REMOTE_SERV="cd000000"
REMOTE_PATH="/usr/guest/bin"
REMOTE_SEARCH_FILE="Hello.txt"
REMOTE_CMD="ls "$MY_FILE
LOCAL_LOG_FILE="/tmp/MY_FTP_SCRIPT.LOG"
> $LOCAL_LOG_FILE

#start ftp
ftp -n $REMOTE_SERV <<-! 2>&1 | tee -i -a $LOCAL_LOG_FILE | grep -i $REMOTE_SEARCH_FILE > /dev/null 2>&1
user $FTP_USER $FTP_PASS
cd $REMOTE_PATH
$REMOTE_CMD
bye
!

GREP_RESULT="$?"

if [ "$GREP_RESULT" = "0" ]
then
echo "file "$REMOTE_SEARCH_FILE" found"
else
echo "file "$REMOTE_SEARCH_FILE" not found"
fi
__________________
Greetings from germany
Peter F.
Reply With Quote
  #6 (permalink)  
Old 03-28-04, 11:03
meenuramesh meenuramesh is offline
Registered User
 
Join Date: Mar 2004
Posts: 5
Exclamation FTP Automation

Hi,

The file search code is not giving any error, the shell script is working fine during run time.

But the problem is what ever file name i give for search, it is saying file found.

I am not getting the code. Can you kindly explain me.
Reply With Quote
  #7 (permalink)  
Old 03-28-04, 13:14
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
First :
there is a little bug in my code.

change REMOTE_CMD="ls "$MY_FILE
to REMOTE_CMD="ls "$REMOTE_SEARCH_FILE

Second:
If the script does not still work, look at the LOCAL_LOG_FILE and give
me a hardcopy of it in case the file surely exist and one when the file surely not exist. May be we do it by another way.
__________________
Greetings from germany
Peter F.
Reply With Quote
  #8 (permalink)  
Old 03-29-04, 06:10
meenuramesh meenuramesh is offline
Registered User
 
Join Date: Mar 2004
Posts: 5
Exclamation FTP Automation

Hi,

The shell script is not giving the correct output, even the file is not exist it is giving file found. in the local log file in the very first line it is saying ?invalid command and then the listing of the files in the ftp server.

Can you pls help me, what went wrong.


Regards,
R.Ramesh.
Reply With Quote
  #9 (permalink)  
Old 03-29-04, 15:05
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi,
we are near by.
Try this :

FTP_USER="guest"
FTP_PASS="guest"
REMOTE_SERV="cd000000"
REMOTE_PATH="/usr/guest/bin"
REMOTE_SEARCH_FILE="hallo3"
REMOTE_CMD="ls"
LOCAL_LOG_FILE="/tmp/MY_FTP_SCRIPT.LOG"
> $LOCAL_LOG_FILE

# FTP starten
ftp -n $REMOTE_SERV <<-! 2>&1 | tee -i -a $LOCAL_LOG_FILE > /dev/null 2>&1
user $FTP_USER $FTP_PASS
cd $REMOTE_PATH
$REMOTE_CMD
bye
!
GREP_RESULT=`grep $REMOTE_SEARCH_FILE $LOCAL_LOG_FILE`
if [ -n "$GREP_RESULT" ]
then
echo "file ==> "$REMOTE_SEARCH_FILE" found"
else
echo "file ==> "$REMOTE_SEARCH_FILE" not found"
fi
echo "."
echo "------------ Output from LOCAL_LOG_FILE ---------"
cat $LOCAL_LOG_FILE | pg
__________________
Greetings from germany
Peter F.
Reply With Quote
  #10 (permalink)  
Old 11-03-04, 02:26
Madhushree Das Madhushree Das is offline
Registered User
 
Join Date: Oct 2004
Posts: 2
I am not able to get the output from the code plz help me out

Hello !


I am also trying to connect to a remote system and get the file by FTP but after getting the file i am unable to do grep in that same file which is downloaded to the path where i have load the program run the FTP of the file.



With regards,

Madhushree
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On