File permission check in SFTP mode


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File permission check in SFTP mode
# 1  
Old 12-22-2010
File permission check in SFTP mode

Hi,

I have requirement to get a file from a remote location using SFTP only if the file has read/write permission either to the user or to the group.

Currently i m taking the ls of the required file and storing it in a flat file to check the file permission.

Please advice is there any way aprt from this to check the file permission in SFTP mode. so that i can avoid few steps.

Thanks in advance, Also please let me know if further details required.

-Ravin
# 2  
Old 12-22-2010
Is this just to avoid errors if you cannot read it? R/W to all is no good?

No, sftp is just ftp is ssh clothing. You could ssh a script to put files into the archival flow based on an ls of the entire dir:
Code:
cd in_dir
echo "
  . ./.profile >/dev/null 2>&1
  cd out_dir
  ls -l | sed '
    s/^-rw.rw.* //
    t
    d
   ' | cpio -oaH crc | gzip -9
 " | ssh2 user@host ksh | gzcat | cpio -idmH crc

# 3  
Old 12-23-2010
Thanks for the reply..

This is to check if the user doesnt have write permission on a file, then he shouldnt be able to get the file.

anyways will check the above code and provide you an update
# 4  
Old 12-23-2010
User might have other write permission, but permission other is ignored if the group is a match, and permissions other and group are ignored if the user is a match. With ssh2 you can change the nose of the pipeline bit to test the write permission:
Code:
for fn in *.txt
do
  if [ -w "$fn" ]
  then
    echo "$fn"
  fi
done | . . .

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to set file transfer in binary mode in SFTP using Expect?

The below is my script. /usr/bin/expect<<EOD spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST expect "sftp>" expect "password:" set timout 15 send "$password\r" expect "sftp>" send "lcd $remotedir\r" expect "sftp>" ... (1 Reply)
Discussion started by: Anilsaggu9
1 Replies

2. UNIX for Beginners Questions & Answers

SFTP file check through a remote host

Hi all, posting my first time, hope not breaking posting rules with it, if yes, let me know. I'm trying to build a script to check a file in an sftp server through a remote server. The intention is to check the file in a sftp host, and if the file is found or not, it should send an email.... (4 Replies)
Discussion started by: MrShinyPants
4 Replies

3. Shell Programming and Scripting

Check for file permission

Hi, I have an array that has several directory paths and file paths. I use a for loop to traverse through the array and check for files and not directories using the if condition. I wish to display all files that have permissions lesser than what the user has specified. For example: ... (14 Replies)
Discussion started by: mohtashims
14 Replies

4. UNIX for Dummies Questions & Answers

Script to check for file size and then sftp

noted down (44 Replies)
Discussion started by: mirwasim
44 Replies

5. Shell Programming and Scripting

SFTP check if file exists

I lookifn for a way to SFTP a file based on the presence of a flag file . The logic is some thing like this in shelling terms IF ]; then download file.DDMM.dat FI The above is just the way of interpreting the logic. Just want to add that i do not have SSh access to the remote... (2 Replies)
Discussion started by: phpsnook
2 Replies

6. Ubuntu

I want to upload file on remote machine in noninteractive mode through SFTP

Hi All, I want to upload file through SFTP in non interactive mode on remote server. please tell me what will have to do in oreder to do SFTP . (1 Reply)
Discussion started by: kulbhushan
1 Replies

7. Shell Programming and Scripting

check for file existence on remote machine using sftp

Hi all, I am a beginner to shell script.Can any one please help me on the below requirement I need to check whether the file (called 3Com_Files_Delivered.txt) exists on the remote mechaine or not? if so i need to copy all the files from there to my local mechaine.Especially i am... (7 Replies)
Discussion started by: narasimha123
7 Replies

8. Shell Programming and Scripting

SFTP file transfer mode question

I am having trouble viewing a file in ASCII after doing a 'get' using SFTP. It appears to have come across as machine language. Does the file have to be in ASCII format prior to the 'get' or is there a way to convert it to ascii after I get it onto my server? I have read where the secure file... (0 Replies)
Discussion started by: wsiefkas
0 Replies

9. Shell Programming and Scripting

sftp - permission setting check

Hello, I am doing a transfer of a file from one HP-UX ( umask : 033 ) server to another HP-UX server ( umask : 033 ) and file got transferred sucessfully. However I could see the file permission gets changed at the receiving end. Would like to know the reason for that? Details below: ... (3 Replies)
Discussion started by: jansat
3 Replies

10. Shell Programming and Scripting

How to check a file whether it is in binay mode or not while doing ftp??

Hi, One bank statement file should be loaded into some tables by using a concurrent program. But if the file is transfered in binary mode i am getting some special characters in the file which is unexpected. so, for that while moving that file data into tables i want to write a script that... (2 Replies)
Discussion started by: sateesh.d
2 Replies
Login or Register to Ask a Question