Example #1
0
        public Task AttachAsync(string targetPath, string unc, SmbShareCredential smbShareCredential)
        {
            var script = $@"
$acctKey = ConvertTo-SecureString -String ""{smbShareCredential.Password}"" -AsPlainText -Force;
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList ""Azure\{smbShareCredential.Username}"", $acctKey;
New-SmbGlobalMapping -Credential $credential -RemotePath {unc};
New-Item -ItemType SymbolicLink -Path {targetPath} -Value {unc};
";

            return(cmdRunner.RunPowershell(script));
        }
        public async Task AttachAsync(string targetPath, string unc, SmbShareCredential smbShareCredential)
        {
            using (var _s = logger.StepDebug(nameof(AttachAsync)))
            {
                // Ensure dir exists
                Directory.CreateDirectory(targetPath);
                var cmd = getLinuxConnectCmd(unc, targetPath, smbShareCredential);
                await cmdRunner.RunExecutable(cmd.Command, cmd.Arguments);

                _s.Commit();
            }
        }
 private static CmdEntry getLinuxConnectCmd(
     string unc,
     string targetPath,
     SmbShareCredential smbShareCredential)
 {
     return(new CmdEntry
     {
         Command = "mount",
         Arguments = new[]
         {
             normalizeUnc(unc),
             targetPath,
             "-t", "cifs",
             "-o",
             $"username={smbShareCredential.Username},password={smbShareCredential.Password}"
             + ",vers=3.0,dir_mode=0777,file_mode=0777,sec=ntlmssp",
         }
     });
 }