We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,289 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Automate FTP session

I want to write a shell script to automate the ftp session, in that it should take the inputs like the server ip , username , password from a different file who path i'll pass.
and also the validations that if the server path exits or not.

1
Contributor
3
Replies
8 Hours
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
nikita.
Light Poster
35 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Like I have a file config.cfg and contains the following data:-

server_IP = 10.18.15.2
username = nikita
password = nikita
file_path = ${HOME}/tools/
file_name = package.tar.gz

nikita.
Light Poster
35 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I have used this script, but its not working :

ftp awk '$1 ~ /server_IP/ { print $3 }' config.cfg  
        ser awk '$1 ~ /user/ { print $3 }' config.cfg
        assword awk '$1 ~ /password/ { print $3 }' config.cfg
        awk '$1 ~ /file_mode/ { print $3 }' config.cfg
        cd awk '$1 ~ /file_path/ { print $3 }' config.cfg
        get awk '$1 ~ /file_name/ { print $3 }' config.cfg
        echo file downloaded
        echo end
        bye
nikita.
Light Poster
35 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I have finally written this code, but the prob with this is that when it is prompting for password it doesnt send any password to the ftp machine, we have to do it manually, but after typing it manually, it take the password line as command and shows that that is invalid command.
please tell me a way to pass the password automatically

CONFIG_FILE="${HOME}/c/config.cfg"
Password=`awk '$1 ~ /password/ { print $3 }' $CONFIG_FILE`
echo $Password
if [ ! -r $CONFIG_FILE ]
then
        echo "File not readable";exit0;
fi

ftp -i `awk '$1 ~ /server_IP/ { print $3 }' $CONFIG_FILE` <<END
`awk '$1 ~ /user/ { print $3 }' $CONFIG_FILE`
`awk '$1 ~ /password/ { print $3 }' $CONFIG_FILE`
`awk '$1 ~ /file_mode/ { print $3 }' $CONFIG_FILE`
cd `awk '$1 ~ /file_path/ { print $3 }' $CONFIG_FILE`
get `awk '$1 ~ /file_name/ { print $3 }' $CONFIG_FILE`
quit
END

the config file is as

server_IP       =       10.18.14.2
user            =       scpyogesh
password        =       scpyogesh
file_mode       =       binary
file_path       =       sample/test/
file_name       =       test_ftp.txt
nikita.
Light Poster
35 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0611 seconds using 2.65MB