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

Automate FTP session

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
Shell Scripting Syntax (Toggle Plain Text)

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
(Toggle Plain Text)

server_IP = 10.18.14.2
user = scpyogesh
password = scpyogesh
file_mode = binary
file_path = sample/test/
file_name = test_ftp.txt

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

If you look at the man pages for ftp it states that you add the account parameter to the command line followed by the password for the account. To look at the manula pages use:

man ftp

from a shell prompt.

rch1231
Veteran Poster
1,045 posts since Sep 2009
Reputation Points: 142
Solved Threads: 154
Skill Endorsements: 12

The ftp command is not designed for use in scripts; it is intended for interactive use. For scripting, use the ncftp family of commands. (There are also some others, I believe, that are made for scripting.)

cfajohnson
Junior Poster
196 posts since Dec 2008
Reputation Points: 25
Solved Threads: 23
Skill Endorsements: 0

Hello,

I hate to disagree with someone on a response but ftp works fine is shell scripts. Typical ftp client programs under Unix, Linux, Solaris and NetBSD all read the ftp password from /dev/tty (or /dev/pty). The following site has a discussion of the issues involved and a script that does what you want.

http://www.stratigery.com/scripting.ftp.html

rch1231
Veteran Poster
1,045 posts since Sep 2009
Reputation Points: 142
Solved Threads: 154
Skill Endorsements: 12

I tried all that mentioned in the page. but it is still not taking the password. as in it just stucks to the point of username. it says the user name is ok but it keeps on blinking for the password. but is not able to pass the password .

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

ok.. its done.. thankz

nikita.
Light Poster
35 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by rch1231 and cfajohnson

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 generated in 0.0697 seconds using 2.66MB