Need to change file permission after SFTP

Advertisement

Jagadish.vr
Joined:
Posts:
1
Location:
India

Need to change file permission after SFTP

hi There,

Unable to change file permission.
Last edited by Jagadish.vr on 2014-10-07 09:01; edited 1 time in total

Reply with quote

Advertisement

Guest

Re: Need to change file permission after SFTP

martin wrote:

What is the problem? Any error message? Or you do not know how?

Thanks for your response. The problem is after I SFTP the file to remote server the file permission is set to 600.

I want to ensure the file transfered to remote server directory is set to "644" after completion of SFTP or set the permissions of all files in remote server directory to "644" [Enable GroupRead] in the same script.



Thanks much
Jagadish V.R

Reply with quote

Guest

HI Martin,

I tried the below , however getting error - Cannot change read-only permmissions.

$directory = $session.ListDirectory("/abc/def/zxyz")

foreach ($fileInfo in $directory.Files)
{

Write-Host ("{0} with size {1}, permissions {2} and last modification at {3}" -f
$fileInfo.Name, $fileInfo.Length, $fileInfo.FilePermissions, $fileInfo.LastWriteTime)

$fileInfo.FilePermissions.Numeric = 644


}

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,453
Location:
Prague, Czechia

Re: Need to change file permission after SFTP

Please attach a session log file showing upload of the file with the TransdferOptions configured to set the permissions. I.e. your original code that you have just removed.

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

Guest

Re: Need to change file permission after SFTP

martin wrote:

Please attach a session log file showing upload of the file with the TransdferOptions configured to set the permissions. I.e. your original code that you have just removed.

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Hi Martin,

I have attached 2 file below. Script and Log file. Issue faced is in the statement mentioned below.

Thanks much for all your support.

$directory = $session.ListDirectory("/roam/SLS/PDPA")
$filePermissions = New-Object WinSCP.TransferOptions

foreach ($filePermissions in $directory.Files)

{
Write-Host (" {0} permissions {1} " -f $filePermissions.Name, filePermissions.FilePermissions)

## Below statement not working ##

$filePermissions.FilePermissions.Octal = 644

}


Cheers
Jagadish V>R
  • WinSCP.log (10.66 KB, Private file)
Description: LOg File
  • Script.txt (2.1 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,453
Location:
Prague, Czechia

Re: Need to change file permission after SFTP

Again, Please attach a session log file showing upload of the file with the TransferOptions configured to set the permissions. I.e. your original code that you have removed from your very first post. That's the only way that works.

You cannot set $filePermissions.FilePermissions.Octal = 644. This won't work. It's read-only by purpose.

Reply with quote

Advertisement

You can post new topics in this forum