Execute() публичный Метод

Executes command specified by CommandText property.
Client is not connected. Operation has timed out.
public Execute ( ) : string
Результат string
Пример #1
0
 private int GetUserId()
 {
     using (var cmd = new SshCommand(Session, "id -u "))
         // Thease commands seems to be POSIX so the only problem would be Windows enviroment
     {
         cmd.Execute();
         return cmd.ExitStatus == 0 ? Int32.Parse(cmd.Result) : -1;
     }
 }
Пример #2
0
        DokanError IDokanOperations.GetDiskFreeSpace(out long free, out long total,
            out long used, DokanFileInfo info)
        {
            //Log("GetDiskFreeSpace");
            LogFSActionInit("GetDiskFreeSpace", this._volumeLabel, (SftpContext)info.Context, "");

            Log("GetDiskFreeSpace");

            var diskSpaceInfo = CacheGetDiskInfo();

            if (diskSpaceInfo != null)
            {
                free = diskSpaceInfo.Item1;
                total = diskSpaceInfo.Item2;
                used = diskSpaceInfo.Item3;
            }
            else
            {
                if (_supportsStatVfs)
                {
                    var information = _sftpSession.RequestStatVfs(_rootpath, true);
                    total = (long) (information.TotalBlocks*information.BlockSize);
                    free = (long) (information.FreeBlocks*information.BlockSize);
                    used = (long) (information.AvailableBlocks*information.BlockSize);
                }
                else
                    using (var cmd = new SshCommand(Session, String.Format(" df -Pk  {0}", _rootpath)))
                        // POSIX standard df
                    {
                        cmd.Execute();
                        if (cmd.ExitStatus == 0)
                        {
                            var values = cmd.Result.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);

                            total = Int64.Parse(values[values.Length - 5]) << 10;
                            used = Int64.Parse(values[values.Length - 4]) << 10;
                            free = Int64.Parse(values[values.Length - 3]) << 10; //<======maybe to cache all this
                        }
                        else
                        {
                            total = 0x1900000000; //100 GiB
                            used = 0xc80000000; // 50 Gib
                            free = 0xc80000000;
                        }
                    }

                CacheAddDiskInfo(new Tuple<long, long, long>(free, total, used),
                        DateTimeOffset.UtcNow.AddMinutes(3));
            }
            LogFSActionSuccess("GetDiskFreeSpace", this._volumeLabel, (SftpContext)info.Context, "Free:{0} Total:{1} Used:{2}", free, total, used);
            return DokanError.ErrorSuccess;
        }
Пример #3
0
 private IEnumerable<int> GetUserGroupsIds()
 {
     using (var cmd = new SshCommand(Session, "id -G "))
     {
         cmd.Execute();
         return cmd.Result.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).Select(Int32.Parse);
     }
 }
Пример #4
0
        private int GetUserId()
        {
            if (!_noSSHCommands)
            {
                using (var cmd = new SshCommand(Session, "id -u ", Encoding.ASCII))
                // Thease commands seems to be POSIX so the only problem would be Windows enviroment
                {
                    cmd.CommandTimeout = TimeSpan.FromSeconds(10);
                    try
                    {
                        cmd.Execute();
                        if (cmd.ExitStatus == 0)
                            return Int32.Parse(cmd.Result);
                    }
                    catch
                    {
                        _noSSHCommands = true;
                    }
                }
            }

            var r = _sftpSession.RequestStat(".", true);
            if (r != null)
                return r.UserId;

            return -1;
        }
Пример #5
0
        private IEnumerable<int> GetUserGroupsIds()
        {
            if (!_noSSHCommands)
            {
                using (var cmd = new SshCommand(Session, "id -G ", Encoding.ASCII))
                {
                    cmd.CommandTimeout = TimeSpan.FromSeconds(10);
                    try
                    {
                        {
                            cmd.Execute();
                            return cmd.Result.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(Int32.Parse);
                        }
                    }
                    catch
                    {
                        _noSSHCommands = true;
                    }
                }
            }

            var r = _sftpSession.RequestStat(".", true);
            if (r != null)
                return new int[] { r.GroupId };

            return new int[0];
        }
Пример #6
0
        DokanError IDokanOperations.GetDiskFreeSpace(out long free, out long total,
                                                     out long used, DokanFileInfo info)
        {
            Log("GetDiskFreeSpace");

            var diskSpaceInfo = _cache.Get(_volumeLabel) as Tuple<long, long, long>;

            if (diskSpaceInfo != null)
            {
                free = diskSpaceInfo.Item1;
                total = diskSpaceInfo.Item2;
                used = diskSpaceInfo.Item3;
            }
            else
            {

                if (_supportsStatVfs)
                {
                    var information = _sftpSession.RequestStatVfs(_rootpath, true);
                    total = (long)(information.TotalBlocks * information.BlockSize);
                    free = (long)(information.FreeBlocks * information.BlockSize);
                    used = (long)(information.AvailableBlocks * information.BlockSize);
                }
                else
                {
                    total = 0x1900000000; //100 GiB
                    used = 0xc80000000; // 50 Gib
                    free = 0xc80000000;

                    if (!_noSSHCommands)
                    {
                        using (var cmd = new SshCommand(Session, String.Format(" df -Pk  {0}", _rootpath), Encoding.ASCII))
                        // POSIX standard df
                        {
                            cmd.CommandTimeout = TimeSpan.FromSeconds(10);

                            try
                            {
                                cmd.Execute();
                                if (cmd.ExitStatus == 0)
                                {
                                    var values = cmd.Result.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                                    total = Int64.Parse(values[values.Length - 5]) << 10;
                                    used = Int64.Parse(values[values.Length - 4]) << 10;
                                    free = Int64.Parse(values[values.Length - 3]) << 10; //<======maybe to cache all this
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                _cache.Add(_volumeLabel, new Tuple<long, long, long>(free, total, used),
                           DateTimeOffset.UtcNow.AddMinutes(3));
            }

            return DokanError.ErrorSuccess;
        }
Пример #7
0
 /// <summary>
 /// Executes command.
 /// </summary>
 /// <returns>Command execution result.</returns>
 public string Execute()
 {
     return(_sshCommand.Execute());
 }