sshnet / sshnet/SSH.NET

How do I create a directory or file with 777 permission and a specific username and group

Open
#973 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

How do I create a directory with 777 permission and a specific username and group


...

 using (SftpClient sftp = new SftpClient(ipSftpServer, portSftpServer, userSftp, passSftp))
                        {
                            sftp.Connect();
                            CreateServerDirectoryIfItDoesntExist(destSftpPath, sftp);
                            memoryStream.Seek(0, SeekOrigin.Begin);
                            sftp.UploadFile(memoryStream, destSftpPath, delegate (ulong d)
                            {
                                if (uploadCallback != null)
                                {
                                    uploadCallback((long)d, bytesTotal);
                                }
                            });
                            // chown -R dcm4chee-arc:dcm4chee-arc .
                            //change user and group dcm4chee-arc dcm4chee-arc
                            sftp.ChangePermissions(destSftpPath, 777);
                            Console.WriteLine($"end of file copy");
                            sftp.Disconnect();
                        }

...
 private static void CreateServerDirectoryIfItDoesntExist(string serverDestinationPath, SftpClient sftpClient)
    {

        string[] directories = serverDestinationPath.Split('/');    
        Array.Resize(ref directories, directories.Length - 1);      
        for (int i = 0; i < directories.Length; i++)
        {
            if (i > 0)
            {
                string dirName = string.Join("/", directories, 0, i + 1);
               
                if (!sftpClient.Exists(dirName))
                {                
                    sftpClient.CreateDirectory(dirName);
                    // chown -R dcm4chee-arc:dcm4chee-arc .
                    //example user and group: dcm4chee-arc dcm4chee-arc
                    //How do I create a directory with 777 permission and a specific username and group
                    sftpClient.ChangePermissions(dirName, 777);
                    
                }
            }
        }
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SftpClient.CreateDirectory, UploadFile, and ChangePermissions calls shown in the issue, and check the SSH.NET API documentation for ownership and permission support. Done means determining whether the requested directory and file ownership behavior is supported and providing an unambiguous usage or limitation answer.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.