Esempio n. 1
0
        public int ReadFile(
            String filename,
            Byte[] buffer,
            ref uint readBytes,
            long offset,
            DokanFileInfo info)
        {
            string path = GetPath(filename);

            if (path.Contains(":SSHFSProperty.Permission"))
            {
                if (offset == 0)
                {
                    string[] tmp = path.Split(new char[] { ':' });
                    path = tmp[0];
                    string str   = ReadPermission(path);
                    byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str);
                    uint   min   = (uint)(buffer.Length < bytes.Length ? buffer.Length : bytes.Length);
                    Array.Copy(bytes, buffer, min);
                    readBytes = min;
                    return(0);
                }
                else
                {
                    readBytes = 0;
                    return(0);
                }
            }

            if (info.IsDirectory)
            {
                return(-1);
            }


            Debug("ReadFile {0} bufferLen {1} Offset {2}", filename, buffer.Length, offset);
            try
            {
                ChannelSftp channel = GetChannel();
                GetMonitor  monitor = new GetMonitor(offset + buffer.Length);
                GetStream   stream  = new GetStream(buffer);
                channel.get(path, stream, monitor, ChannelSftp.RESUME, offset);
                readBytes = (uint)stream.RecievedBytes;
                Debug("  ReadFile readBytes: {0}", readBytes);
                return(0);
            }
            catch (SftpException)
            {
                return(-1);
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return(-1);
            }
        }
Esempio n. 2
0
        public int ReadFile(
            String filename,
            Byte[] buffer,
            ref uint readBytes,
            long offset,
            DokanFileInfo info)
        {
            string path = GetPath(filename);

            if (path.Contains(":SSHFSProperty.Permission"))
            {
                if (offset == 0)
                {
                    string[] tmp = path.Split(new char[] { ':' });
                    path = tmp[0];
                    string str = ReadPermission(path);
                    byte[] bytes = System.Text.Encoding.ASCII.GetBytes(str);
                    uint min = (uint)(buffer.Length < bytes.Length ? buffer.Length : bytes.Length);
                    Array.Copy(bytes, buffer, min);
                    readBytes = min;
                    return 0;
                }
                else
                {
                    readBytes = 0;
                    return 0;
                }
            }

            if (info.IsDirectory)
                return -1;


            Debug("ReadFile {0} bufferLen {1} Offset {2}", filename, buffer.Length, offset);
            try
            {
                ChannelSftp channel = GetChannel();
                GetMonitor monitor = new GetMonitor(offset + buffer.Length);
                GetStream stream = new GetStream(buffer);
                channel.get(path, stream, monitor, ChannelSftp.RESUME, offset);
                readBytes = (uint)stream.RecievedBytes;
                Debug("  ReadFile readBytes: {0}", readBytes);
                return 0;
            }
            catch (SftpException)
            {
                return -1;
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return -1;
            }
        }