Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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.
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
martin

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


}
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
martin

Re: Need to change file permission after SFTP

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

Need to change file permission after SFTP

hi There,

Unable to change file permission.