Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
+1 vote
527 views
in Java FTP by (290 points)

One of our customer have a requirement that uploaded files needs to have 660 file permission. This is working for them when using the old version of our product (with edtFTPj/PRO v2.1.2), but they need to upgrade now. 

I know that you could update the file permissions by using InvokeSiteCommand( ). We tried that but we are getting an error: "Custom command result 200 This service allow sftp connections only". I read around and I think this is because their server have this configuration: ForceCommand internal-sftp

My question is:

What is the default file permissions of the uploaded files? Is it 755? Is there a configuration or setting to change this to a different permission so that we don't need to do the InvokeSiteCommand?

1 Answer

0 votes
by (51.1k points)
selected by
 
Best answer
I'm going to assume that you're using FTP or FTPS, since you don't really say.

There are no defaults for FTP. The problem is that the FTP protocol doesn't deal with permissions, so there are no commands for handling them nor even any rules for what the defaults are supposed to be. It's therefore up to each individual server to determine how they should be handled, which is done via SITE commands.

SFTP does have permission commands and rules, so if you were to use that protocol (which our client supports) then you'd have some options.

Having said that, I don't see why upgrading edtFTPj/PRO to a more recent version should break anything, so if it worked with the old client then it should work with the new client.
by (290 points)
I am connecting using (S)FTP. I did some further tests transferring files using Filezilla, command line sftp and via edtFTPj/pro library. Here are the resulting file permissions.
-rw-rw-r--    1 ftpUser  ftpUser        11 Jun 22 23:43 file1.txt
-rw-rw-r--    1 ftpUser  ftpUser         9 Jun 22 23:51 file2.txt
-rw-rw-r--    1 ftpUser  ftpUser        27 Jun 23 04:06 msg.txt
-rwxr-xr-x    1 ftpUser  ftpUser        27 Jun 23 03:56 upload.txt

file1.txt and file2.txt was transferred using Filezilla
msg.txt using command line SFTP
upload.txt using edtFTPj/pro

So why are the files transferred by edt different? Now, I did a debug log and saw this line:
[DEBUG] {(S)FTP Client 2 [251, 0] OUTPUT} (com.enterprisedt.SftpClient) chmod(755,/home/ftpUser/REN46663/upload.txt)
[DEBUG] {(S)FTP Client 2 [251, 0] OUTPUT} (com.enterprisedt.SftpClient) chmod(actual=/home/ftpUser/REN46663/upload.txt)

So I disabled chmod after transfer and create directory, but the resulting permission is still the same, -rwxr-xr-x:
[DEBUG] {(S)FTP Client 2 [251, 0] OUTPUT} (com.enterprisedt.SSHFTPClient) DISABLE_CHMOD_AFTER_PUT is set
[DEBUG] {(S)FTP Client 2 [251, 0] OUTPUT} (com.enterprisedt.SSHFTPClient) DISABLE_WAIT_FOR_CHANNEL_CLOSE is set
[DEBUG] {(S)FTP Client 2 [251, 0] OUTPUT} (com.enterprisedt.SSHFTPClient) DISABLE_CHMOD_AFTER_CREATE_DIR is set

I did a code debug of com.enterprisedt.net.j2ssh.SftpClient.put( ) and got this:
FileAttributes attr = new FileAttributes();
permissions = new UnsignedInteger32(default_permissions & ~umask);
attr.setPermissions(permissions);

So, is this where we are getting that file permission 755?

For my tests above, which one is using the correct file permission? Is it edt or Filezilla and command line sftp?
by (161k points)
You need to change the umask - that's what controls the permissions that are set.
by (290 points)
Thanks for the reply. Can you tell me where or how do I actually set this?
by (8.1k points)
by (290 points)
Thanks Stuart. But how do I do it in the program using library? site( )? executeCommand()?
by (161k points)
Use setUmask() to set it locally in the client.

Categories

...