Execute() public method

Executes command specified by CommandText property.
Client is not connected. Operation has timed out.
public Execute ( ) : string
return string
コード例 #1
0
ファイル: SftpFilesystem.cs プロジェクト: cpascal/win-sshfs
 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
ファイル: SftpFilesystem.cs プロジェクト: cpascal/win-sshfs
        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
ファイル: SftpFilesystem.cs プロジェクト: cpascal/win-sshfs
 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
ファイル: SftpFilesystem.cs プロジェクト: kenkendk/win-sshfs
        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
ファイル: SftpFilesystem.cs プロジェクト: kenkendk/win-sshfs
        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
ファイル: SftpFilesystem.cs プロジェクト: kenkendk/win-sshfs
        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
ファイル: SshCommand.cs プロジェクト: waffle-iron/nequeo
 /// <summary>
 /// Executes command.
 /// </summary>
 /// <returns>Command execution result.</returns>
 public string Execute()
 {
     return(_sshCommand.Execute());
 }