Archived Forum Post

Index of archived forum posts


How to chmod Permissions for File on SFTP Server?

Sep 11 '15 at 08:47

I’m using ChilkatSFTP ActiveX object for transferring file over sFTP. I have this requirement where we have to issue a command (chmod 640 <filename>) after uploading the file on to the destination server.

Does your ActiveX component support issuing such commands on the destination server?


Assuming you're asking about the Chilkat SSH/SFTP file transfer (meaning Secure File Transfer over SSH), then the answer is Yes. The SetPermissions method can be called after the upload to set the remote file permissions. Permissions on Linux/Unix boxes are written in octal format, so 640 is really an octal number. The same number in decimal format = 68^2 + 48 + 0 = 416. Therefore, you would pass the decimal integer 416 to the "permissions" argument to SetPermissions.


I'm going to answer my own question. The error is happening because my3rd parameter should be passed in Decimal rather than octal.

In my case, 644 converts to 420.

However one thing I didn't understand: How should we use the GetFilePermissions? This function returns an integer. I thought that it would be a decimal. However when I used it for a file, I received a value of 3188. What kind of value is that and how can I use it?


Let's say I have an integer variable that holds a 32-bit value. One cannot say that the integer is "octal" or "decimal" or "hex". It is simply a 32-bit integer. It can be represented in character string form as octal, decimal, or hex, depending on how one groups the bits to form the chars. If I group bits 3 at a time and assign the symbols 0-7 for each 3-bit grouping, I'm showing the octal representation of the integer. If I group bits 4 at a time and assign the symbols 0-9A-F for each 4-bit grouping, then I'm showing the hex representation. The decimal representation wouldn't be an integral grouping of bits..

The answer is that you use bit operators to examine the bits of the 32-bit integer. Again, an integer cannot be said to be "decimal" or "octal", etc. It is only the string representation of the integer that can be said to be decimal, octal, etc.