Operating System - HP-UX
1833704 Members
3197 Online
110062 Solutions
New Discussion

Re: How to call automaticly a script when a ftp file is recieved

 
Equipe hebergement
Occasional Advisor

How to call automaticly a script when a ftp file is recieved

Whe have sereval ftp users (ftp only users) that put files on our server, and we must process those files automaticly.
For the moment, an application check every x minutes if a file is arrived. But there is too much users, and it takes times and load the machine.

How can we make an automated script when a file is recieved ? Without monitoring the log file, is there a more elegant solution ?
5 REPLIES 5
Michael Steele_2
Honored Contributor

Re: How to call automaticly a script when a ftp file is recieved

Use the macdef command from ftp and .netrc to execute commands to be processed after the transfer. After the 'put' or 'mput'. Call the executable in this fashion.

On UN*X systems, you have to use the file
"$HOME/.netrc"

and on Windows systems (client-wise speaking) there
is an command-line option for it.

/home/ftpuser
$HOME/.netrc

machine SERVER login USER password SECRET macdef init
cd /remote-dir
lcd /local-dir
prompt
binary
mput *.*
exexcutable_script
quit
Support Fatherhood - Stop Family Law
Michael Steele_2
Honored Contributor

Re: How to call automaticly a script when a ftp file is recieved

Use the macdef command from ftp and .netrc to execute commands to be processed after the transfer. After the 'put' or 'mput'. Call the executable in this fashion.

For example,

home/ftpuser
$HOME/.netrc

machine SERVER login USER password SECRET macdef init
cd /remote-dir
lcd /local-dir
prompt
binary
mput *.*
'Call-to-exexcutable_script_goes_here'
quit
Support Fatherhood - Stop Family Law
Equipe hebergement
Occasional Advisor

Re: How to call automaticly a script when a ftp file is recieved

Sorry, but I don't understand how the macdef command can solve my problem.
English is not my native language.

A remote user send a file via FTP on our server.
The server should process this file, so the server should detect that there is a new file and launch a script.

Does I wrong understand you ?
Michael Steele_2
Honored Contributor

Re: How to call automaticly a script when a ftp file is recieved

I can't find my example now but here is an alternative.

Put ftp in the sending machine and use the .netrc procedure provided above minus the 'Call-to-exexcutable_script_goes_here'.

Next line put a remsh to invoke the executable from the sending machine into the destination machine where you've just placed the files.

crontab
0 * * * * $HOME/transfer_script

From transfer machine:

Inside transfer_script:

#!/usr/bin/ksh

ftp destination machine
remsh destination machine executable

From destination machine:
.netrc
See above minus 'call...'

Support Fatherhood - Stop Family Law
Becke
Super Advisor

Re: How to call automaticly a script when a ftp file is recieved

Hi everyone,

I have written a korn shell automated script which only transfer files, but how do I transfer all the subdirectories in the filesystem.

Any help would be greatly appreciated. Below is my script.
#!/usr/bin/ksh
cd /FILESYSTEM_NAME
USER=root
PASS=1234
MACHINE=hostname
FTP=/usr/bin/ftp
$FTP -n $MACHINE </dev/null 2>$1
user $USER $PASS
ascii
cd /FILESYSTEM_NAME
mput *

The above script works fine, but what do i need to do in the script so it transfer all the files in the subdirectories of /FILESYSTEM_NAME. Please advise