Topic "Need to change file permission after SFTP"

Author Message
Jagadish.vr
[View user's profile]

Joined: 2014-10-03
Posts: 1
Location: India
hi There,

Unable to change file permission.

Last edited by Jagadish.vr on 2014-10-07 09:01; edited 1 time in total
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24995
Location: Prague, Czechia
What is the problem? Any error message? Or you do not know how?
_________________
Martin Prikryl
Guest




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


}
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24995
Location: Prague, Czechia
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




prikryl 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

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24995
Location: Prague, Czechia
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.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License