Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How do i skip the user login when i try to do a ftp in shell script? if i do the ftp at the command prompt, i will hit on the carriage return when the login is prompted.
a normal ftp script would looks like this:
#!/bin/kshHOST='12.34.56.67'
USER='userid'
PASSWD='password'
FILE='file.txt'
ftp -n $HOST END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

Create a file .netrc in your users $HOME dir
write to that file:
machine remotehostname login userid password useridpassword
fill in the blanks for remotehostname, userid, and useridpassword.
save the file and ftp to remotehostname

create a .netrc file with the following info in the $HOME directory of the user the script will be ran by.
.netrc
::::::::::
machine remotehost login username password pass123Then:
1. create your primary script that gathers and sets the variables. Have that script dynamically create the temporary ftp script through
set DATE=`date +%Y%m%d%H%M`
echo "ftp hostname 1>/dev/null 2>&1 EOF" > tmp_ftp.sh
echo "lcd /local/dir/of/files" >> tmp_ftp.sh
echo "cd /remote/dir/to/put/files" >> tmp_ftp.sh
echo "prompt off" >> tmp_ftp.sh
echo "mput *.${DATE}" >> tmp_ftp.sh
echo "quit" >> tmp_ftp.sh# Change permissions of your temp script
chmod 744 tmp_ftp.sh
# Then run that script you just wrote.
tmp_ftp.sh# you can rm the temp script or just leave it so long as the first echo is redirected with a single ">" for overwrite mode and all others are ">>" for append mode.

thanks Satalink! but theres no login for the particular hostname that i want to connect for the ftp transfer. I cant leave the username as '' or '\\c'. It will cause error when i execute the script

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |