Page 1 of 1

Changing file Permission through shell script by Ftp process

Posted: Wed Oct 05, 2005 5:11 am
by khanparwaz
Hi,

Currently i am Using A shell script to ftp to a Nt Server from where i am getting the files & after loading i am Archieving that file to a diffrent folder
on the same Nt server & then Again using a shell script to delete the file from the original location.

Now the problem with me is that i am manually making the file as read only after Archieving that, i want to implement this using shell script too.
is their any way i can implement that in shell script ,chmod command i ve already tried but that dont wotk On ftp prompt any other way to make file as read only.

Thanks In Advance :wink:

Posted: Wed Oct 05, 2005 6:01 am
by kduke
You have to do it after ftp is done. chmod is not a command within the ftp command.

Posted: Wed Oct 05, 2005 6:06 am
by ArndW
Doesn't the file automatically receive the remote file user's login umask? That might be changed to limit access.

Posted: Wed Oct 05, 2005 6:35 am
by khanparwaz
kduke wrote:You have to do it after ftp is done. chmod is not a command within the ftp command.
its Ok That mean i have to do it manually their is no way to automate this
through data stage coz ftp stage doesn't support any such options of changing file permissions. :?:

Posted: Wed Oct 05, 2005 7:01 am
by chulett
As long as the remote server allows it, there are the 'Telnet before' and 'Telnet after' commands available inside the FTP stage. Setup the 'after' session to log in and issue the chmod command.

Posted: Wed Oct 05, 2005 8:40 am
by khanparwaz
chulett wrote:As long as the remote server allows it, there are the 'Telnet before' and 'Telnet after' commands available inside the FTP stage. Setup the 'after' session to log in and issue the chmod command.

Hi craig can u tell me exactly wat should i specify in that option to change the permission or should i directly fire that chmod command in telnet after session option.

Posted: Wed Oct 05, 2005 9:10 am
by chulett
The same series of steps you would have to do if you were telnet'ing into the box after the ftp and changing the permissions yourself.

Posted: Wed Oct 05, 2005 9:33 am
by khanparwaz
chulett wrote:The same series of steps you would have to do if you were telnet'ing into the box after the ftp and changing the permissions yourself.
But the problem here is when i try to telnet that server from command prompt its says Could not open a connection to host: Connect failed.
Might be server was not configured for recieving incoming telnet sessions.
:x .Is their a way of doing it through some script.

Posted: Wed Oct 05, 2005 11:12 am
by ketfos
Hi,
Can you tell us your scirpt for ftp and archiving the files.

ketfos

Posted: Thu Oct 06, 2005 2:59 am
by khanparwaz
Hi ketfos,

Archieving i am doin just by Ftp>ftp stage so its just creating a similar copy to another folder then after completing this job i am deleting the file from original location by using shell script ,in that i am using delete command to delete the file [#!/bin/sh
HOST=$1
USER=$2
PASSWD=$3

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
delete /ftp_mxg2000/$4
quit
END_SCRIPT
exit 0][/code]

Posted: Thu Oct 06, 2005 4:35 am
by cmmurari
you can use command stage in server jobs

Posted: Thu Oct 06, 2005 4:45 am
by khanparwaz
cmmurari wrote:you can use command stage in server jobs
See the exact problem of mine in the beginning :oops: i know i can use command stage for shell script my problem is that how can i change file permission if i archieve a file to some other folder
i want to make it read only after successful transfer.


can any one give better solution]

Thanks

Posted: Thu Oct 06, 2005 11:36 am
by ketfos
Hi Khanparwaz,

Since you ahve mentioned that you want to do change file permission only after successful transfer so -

1. Redirect the output of ftp to file say ftplogfile by using a redirection (>) in your orignal ftp script.

2. Second step is you need to check for successful file transfer.

After quit command in the script,
you can call another shell script. In this script you should check as

ftp_return_code=`grep -i "226 Transfer complete." /ftplogfile | wc -l`

if [[ $ftp_return_code -ne 1 ]]

(note - assumed only 1 file is being ftp'ed)

then echo " FILE CREATION FAILED"

else
chmod command
fi

Posted: Thu Oct 06, 2005 3:22 pm
by clshore
I have seen some ftp that suppport umask for the target files.

But most ftp implementations support some kind of local shell capability, so you can say something like this in your ftp script after the files have been recieved.

....
get $filename
....
! chmod 111 $filename
....

Check the documentation for the ftp on your host.

Carter

Posted: Fri Oct 07, 2005 9:20 am
by khanparwaz
clshore wrote:I have seen some ftp that suppport umask for the target files.

But most ftp implementations support some kind of local shell capability, so you can say something like this in your ftp script after the files have been recieved.

....
get $filename
....
! chmod 111 $filename
....

Check the documentation for the ftp on your host.

Carter

Hi Carter Thanks for reply
But still i am in problem my ftp server is on NT box & ds server is unix
so by command ! chmod it takes me back to unix prompt again & as error i get can't access file one more thing i want to tell you that i can not telnet
the ftp server too & with these conditions i have to change file permissions.