SetFilePermissions Method  
 

Change the access permissions for a file on the server.

Syntax

object.SetFilePermissions( RemoteFile, FilePerms )

Parameters

RemoteFile
A string that specifies the name of the file that the access permissions are to be returned for. The filename cannot contain any wildcard characters.
FilePerms
A numeric value which specifies the new permissions for the file. The file permissions are represented as bit flags, and may be one or more of the following values:
Value Constant Description
1 filePermWorldExecute All users have permission to execute the contents of the file. If this permission is set for a directory, this may also grant all users the right to open that directory and search for files in that directory.
2 filePermWorldWrite All users have permission to open the file for writing. This permission grants any user the right to replace the file. If this permission is set for a directory, this grants any user the right to create and delete files.
4 filePermWorldRead All users have permission to open the file for reading. This permission grants any user the right to download the file to the local system.
8 filePermGroupExecute Users in the specified group have permission to execute the contents of the file. If this permission is set for a directory, this may also grant the user the right to open that directory and search for files in that directory.
16 filePermGroupWrite Users in the specified group have permission to open the file for writing. On some platforms, this may also imply permission to delete the file. If the current user is in the same group as the file owner, this grants the user the right to replace the file. If this permission is set for a directory, this grants the user the right to create and delete files.
32 filePermGroupRead Users in the specified group have permission to open the file for reading. If the current user is in the same group as the file owner, this grants the user the right to download the file.
64 filePermOwnerExecute The owner has permission to execute the contents of the file. The file is typically either a binary executable, script or batch file. If this permission is set for a directory, this may also grant the user the right to open that directory and search for files in that directory.
128 filePermOwnerWrite The owner has permission to open the file for writing. If the current user is the owner of the file, this grants the user the right to replace the file. If this permission is set for a directory, this grants the user the right to create and delete files.
256 filePermOwnerRead The owner has permission to open the file for reading. If the current user is the owner of the file, this grants the user the right to download the file to the local system.

Return Value

A value of zero is returned if the operation was successful, otherwise a non-zero error code is returned which indicates the cause of the failure.

Remarks

The SetFilePermissions method uses the SITE CHMOD command to set the permissions for the file. This command is typically only supported on servers that are hosted on UNIX based systems. If the command is not supported, an error will be returned. You can use the Features property to determine what features are available and/or enabled on the server.

Users who are familiar with the UNIX operating system will recognize the chmod command used to change the file permissions. However, it should be noted that the numeric value used as an argument to the command is in octal, not decimal. For example, issuing the command chmod 644 filename.txt on a UNIX based system will make the file readable and writable by the owner, and readable by other users in the owner's group as well as all other users. The value 644 is an octal value, which is equivalent to the decimal value 420. If you were to mistakenly specify 644 as the value for the Permissions argument, rather than the decimal value of 420, the permissions on the file would be incorrect. It is strongly recommended that you use the pre-defined constants to prevent this sort of error.

Visual Basic allows you to specify an integer value in octal by prefixing it with &O. For example, &O644 could be used as the file permissions value. C and C++ consider any integer with a preceding 0 to be an octal number, so 0644 would be a valid permissions value. Consult the technical reference for your programming language if you are unsure if it supports expressing integer constants in octal.

Example

The following example demonstrates how to change the permissions so that only the owner can read and write to the file:

nFilePerms = filePermOwnerRead Or filePermOwnerWrite
nError = FileTransfer1.SetFilePermissions(strFileName, nFilePerms)
If nError > 0 Then
    MsgBox FileTransfer1.LastErrorString, vbExclamation
    Exit Sub
End If

See Also

Features Property, GetFilePermissions Method