Running a script for every ftp session

Hello all,

I have written a shell script which would prompt the user to enter some name and a folder would be created by that name.
This script should run automatically when the users provide there credentials during a FTP session and for every FTP session.
And after they have provided there credentials they should be inside this newly created folder. Is this possible? If yes, how can I achieve this?

Thanks.

You will have to intercept ftp open calls. We do this with an alias. If the user specifies /usr/bin/ftp this approach will not work.

In /etc/profile add a line like this

alias ftp=/usr/bin/local/ftp.sh

When a user enters ftp, the user actually runs the shell script, not /usr/bin/ftp.
I'm a little fuzzy on the other requirements.

And if I don't have it wrong ftp.sh would be the script that I want to run?

Yes, ftp.sh is the script you want to write, and then run, in place of the real /usr/bin/ftp.
A simple version might look like:

#!/bin/ksh

args="$*"
echo "enter local directory \c"
read locdir
[[ -d $locdir ]] || mkdir $locdir
cd $locdir
/usr/bin/ftp  $args
return $?

Thanks for the reply.
Even I had written a similar script but the cd part of does not seem to work.
Any suggestions?

Thanks.

There are two kinds of paths

# relative path
../myhome
#absolute path
/home/john/smith/myhome

This is the main bugaboo with using cd inside a script... the cd <path> has to have <path> be absolute to always work correctly. Otherwise you have a bigger problem trying to get to the directory.

The other problem is that sometimes users want to go where no man has gone before - so mkdir and cd will fail. You have to check return status if [ $? -eq 0 ] --- everytime you do anything with what originated as user input. User input has to be considered poison. Unfortunately.