The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem to auto mount on NFS server blesets Linux 5 11-10-2007 08:01 PM
su auto run help Ehab UNIX for Dummies Questions & Answers 3 09-24-2007 05:46 AM
Auto FTP from UNIX to Windows Server songtam High Level Programming 1 04-07-2006 04:26 AM
auto run whatisthis Shell Programming and Scripting 1 11-24-2004 04:12 PM
Sun solaris server auto reboots mnjanje UNIX for Dummies Questions & Answers 3 01-23-2002 06:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-17-2006
Registered User
 

Join Date: Feb 2006
Posts: 47
Auto FTP to a server

Hi,

I am trying to automate FTP login to a remote server and put a file there. But no matter what i do, It still is aksing me for the login and password although i have it defined in the variable.

Quote:
SERVER=123.456.789
USER=root
PASSWD=password


if [ $# -eq 0 ]
then
echo "Usage ./ftp.sh <file name>"
exit 0
fi

ftp $SERVER
user $USER $PASSWD
cd /usr/local/home/abc
binary
put testfile

wait
exit 0
Could you tell me what is wrong with this script. I am doing this on SUN server.

Pls assist.

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 03-17-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
All those ftp commands should be within a here-document. Or use the co-process technique.

You should find them in the FAQ section.
Reply With Quote
  #3  
Old 03-17-2006
Registered User
 

Join Date: Feb 2006
Posts: 47
Thank you so much VINO as always, you have been very helpful

3 cheers to you !
Reply With Quote
  #4  
Old 03-17-2006
Registered User
 

Join Date: Feb 2006
Posts: 47
One more thing vino,

If i need to read the codes for FTP how can i do that ..for example

Quote:
220 svpkg1-nd FTP server () ready.
331 Password required for admin1.
230 User admin1 logged in.
250 CWD command successful.
200 PORT command successful.
550 tatu: No such file or directory.
221 Goodbye.
I need to validate on code 550 and echo a message that the specified file was not found.

How can we do this.

Thanks once again
Reply With Quote
  #5  
Old 03-17-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Search the forum with the keywords "ftp result code". You will find a couple of posts which will help you out.
Reply With Quote
  #6  
Old 03-21-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 255
I have ready script

I have automated that FTP script few days back and i think ur requirements are almost same...if ur prob is not yet solved will give u that script
Reply With Quote
  #7  
Old 03-21-2006
Registered User
 

Join Date: Feb 2006
Posts: 47
Hi Dhruv,

Please do share it here, Will be handy for every one.

Any ways, here is how i did it :-

Quote:
#!/bin/sh

# Variables that will be used.

SERVER=12.456.789
USER=username
PASSWD=password
PATH=/your/path/here

#Check if a valid input has been given

if [ $# -eq 0 ]
then
echo "Usage ./getftp.sh <file name to get>"
exit 0
fi

#Connecting via FTP to fetch a desired file.

/usr/bin/ftp -v -n "$SERVER" << cmd
user "$USER" "$PASSWD"
cd $PATH
binary
get $1
quit
cmd
echo "\n FTP session closed "

#Make Sure if the file has reached destination.

if [ -f $1 ]
then
echo "\n Hueston we have received the package\n"
else
echo "\n Oh oo..$1 does not exist on source"
fi

#Start your Validation.

exit 0
Hope this helps some one

Cheers !!!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0