Changing file Permission through shell script by Ftp process

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Changing file Permission through shell script by Ftp process

Post 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:
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

You have to do it after ftp is done. chmod is not a command within the ftp command.
Mamu Kim
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Doesn't the file automatically receive the remote file user's login umask? That might be changed to limit access.
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post 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. :?:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post 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.
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Hi,
Can you tell us your scirpt for ftp and archiving the files.

ketfos
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post 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]
cmmurari
Participant
Posts: 34
Joined: Sun Jan 02, 2005 9:55 am
Location: Singapore

Post by cmmurari »

you can use command stage in server jobs
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post 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
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post 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
clshore
Charter Member
Charter Member
Posts: 115
Joined: Tue Oct 21, 2003 11:45 am

Post 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
khanparwaz
Participant
Posts: 60
Joined: Tue Jul 12, 2005 3:34 am

Post 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.
Post Reply