当前位置: 首页>>代码示例>>C#>>正文


C# String.GetBytes方法代码示例

本文整理汇总了C#中String.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# String.GetBytes方法的具体用法?C# String.GetBytes怎么用?C# String.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在String的用法示例。


在下文中一共展示了String.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: put

        public OutputStream put(String dst, SftpProgressMonitor monitor, int mode, long offset)
        {
            dst = remoteAbsolutePath(dst);
            try
            {
                ArrayList v = glob_remote(dst);
                if (v.Count != 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }
                dst = (String)(v[0]);
                if (isRemoteDir(dst))
                {
                    throw new SftpException(SSH_FX_FAILURE, dst + " is a directory");
                }

                long skip = 0;
                if (mode == RESUME || mode == APPEND)
                {
                    try
                    {
                        SftpATTRS attr = stat(dst);
                        skip = attr.getSize();
                    }
                    catch (Exception) { }
                }

                if (mode == OVERWRITE)
                {
                    sendOPENW(dst.GetBytes());
                }
                else
                {
                    sendOPENA(dst.GetBytes());
                }

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;

                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                if (type == SSH_FXP_STATUS)
                {
                    int i = buf.getInt();
                    throwStatusError(buf, i);
                }

                byte[] handle = buf.getString(); // filename

                //long offset=0;
                if (mode == RESUME || mode == APPEND)
                {
                    offset += skip;
                }

                long[] _offset = new long[1];
                _offset[0] = offset;
                OutputStream outs = new OutputStreamPut(this, handle, _offset, monitor);

                return outs;
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:74,代码来源:ChannelSftp.cs

示例2: unquote

 internal static String unquote(String _path)
 {
     byte[] path = _path.GetBytes();
     int pathlen = path.Length;
     int i = 0;
     while (i < pathlen)
     {
         if (path[i] == '\\')
         {
             if (i + 1 == pathlen)
                 break;
             Array.Copy(path, i + 1, path, i, path.Length - (i + 1));
             pathlen--;
             continue;
         }
         i++;
     }
     if (pathlen == path.Length) return _path;
     byte[] foo = new byte[pathlen];
     Array.Copy(path, 0, foo, 0, pathlen);
     return new JavaString(foo);
 }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:22,代码来源:Util.cs

示例3: get

        public InputStream get(String remoteAbsolutePath, SftpProgressMonitor monitor, int mode)
        {
            if (mode == RESUME)
            {
                throw new SftpException(SSH_FX_FAILURE, "faile to resume from " + remoteAbsolutePath);
            }
            remoteAbsolutePath = this.remoteAbsolutePath(remoteAbsolutePath);
            try
            {
                ArrayList v = glob_remote(remoteAbsolutePath);
                if (v.Count != 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }
                remoteAbsolutePath = (String)(v[0]);

                SftpATTRS attr = GetPathAttributes(remoteAbsolutePath);
                if (monitor != null)
                {
                    monitor.init(SftpProgressMonitor.GET, remoteAbsolutePath, "??", attr.getSize());
                }

                sendOPENR(remoteAbsolutePath.GetBytes());

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                if (type == SSH_FXP_STATUS)
                {
                    int i = buf.getInt();
                    throwStatusError(buf, i);
                }

                byte[] handle = buf.getString(); // filename

                InputStream ins = new InputStreamGet(this, handle, monitor);
                return ins;
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:52,代码来源:ChannelSftp.cs

示例4: mkdir

        public void mkdir(String path)
        {
            path = remoteAbsolutePath(path);

            sendMKDIR(path.GetBytes(), null);

            Header _header = new Header();
            _header = header(buf, _header);
            int length = _header.length;
            int type = _header.type;
            buf.rewind();
            fill(buf.buffer, 0, length);

            if (type != SSH_FXP_STATUS)
            {
                throw new SftpException(SSH_FX_FAILURE, "");
            }

            int i = buf.getInt();
            if (i == SSH_FX_OK) return;
            throwStatusError(buf, i);
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:22,代码来源:ChannelSftp.cs

示例5: _put

        private void _put(InputStream src, String dst, SftpProgressMonitor monitor, int mode)
        {
            try
            {
                long skip = 0;
                if (mode == RESUME || mode == APPEND)
                {
                    try
                    {
                        SftpATTRS attr = GetPathAttributes(dst);
                        skip = attr.getSize();
                    }
                    catch (Exception) { }
                }
                if (mode == RESUME && skip > 0)
                {
                    long skipped = src.skip(skip);
                    if (skipped < skip)
                    {
                        throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + dst);
                    }
                }
                if (mode == OVERWRITE)
                {
                    sendOPENW(dst.GetBytes());
                }
                else
                {
                    sendOPENA(dst.GetBytes());
                }

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
                {
                    throw new SftpException(SSH_FX_FAILURE, "invalid type=" + type);
                }
                if (type == SSH_FXP_STATUS)
                {
                    int i = buf.getInt();
                    throwStatusError(buf, i);
                }
                byte[] handle = buf.getString(); // filename
                byte[] data = null;

                bool dontcopy = true;

                if (!dontcopy)
                {
                    data = new byte[buf.buffer.Length
                                    - (5 + 13 + 21 + handle.Length
                                       + 32 + 20 // padding and mac
                                      )
                        ];
                }

                long offset = 0;
                if (mode == RESUME || mode == APPEND)
                {
                    offset += skip;
                }

                int startid = seq;
                int _ackid = seq;
                int ackcount = 0;
                while (true)
                {
                    int nread = 0;
                    int s = 0;
                    int datalen = 0;
                    int count = 0;

                    if (!dontcopy)
                    {
                        datalen = data.Length - s;
                    }
                    else
                    {
                        data = buf.buffer;
                        s = 5 + 13 + 21 + handle.Length;
                        datalen = buf.buffer.Length - s
                                  - 32 - 20; // padding and mac
                    }

                    do
                    {
                        nread = src.Read(data, s, datalen);
                        if (nread > 0)
                        {
                            s += nread;
                            datalen -= nread;
                            count += nread;
                        }
                    } while (datalen > 0 && nread > 0);
                    if (count <= 0) break;
//.........这里部分代码省略.........
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:101,代码来源:ChannelSftp.cs

示例6: _setStat

        private void _setStat(String path, SftpATTRS attr)
        {
            try
            {
                sendSETSTAT(path.GetBytes(), attr);

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_STATUS)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                int i = buf.getInt();
                if (i != SSH_FX_OK)
                {
                    throwStatusError(buf, i);
                }
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:29,代码来源:ChannelSftp.cs

示例7: _get

        ///tamir: updated to jcsh-0.1.30
        private void _get(String src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip)
        {
            try
            {
                sendOPENR(src.GetBytes());

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;

                buf.rewind();

                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
                {
                    throw new SftpException(SSH_FX_FAILURE, "Type is " + type);
                }

                if (type == SSH_FXP_STATUS)
                {
                    int i = buf.getInt();
                    throwStatusError(buf, i);
                }

                byte[] handle = buf.getString(); // filename

                long offset = 0;
                if (mode == RESUME)
                {
                    offset += skip;
                }

                int request_len = 0;

                while (true)
                {
                    request_len = buf.buffer.Length - 13;
                    if (server_version == 0)
                    {
                        request_len = 1024;
                    }
                    sendREAD(handle, offset, request_len);

                    _header = header(buf, _header);
                    length = _header.length;
                    type = _header.type;

                    int i;
                    if (type == SSH_FXP_STATUS)
                    {
                        buf.rewind();
                        fill(buf.buffer, 0, length);
                        i = buf.getInt();
                        if (i == SSH_FX_EOF)
                        {
                            goto BREAK;
                        }
                        throwStatusError(buf, i);
                    }

                    if (type != SSH_FXP_DATA)
                    {
                        goto BREAK;
                    }

                    buf.rewind();
                    fill(buf.buffer, 0, 4);
                    length -= 4;
                    i = buf.getInt(); // length of data
                    int foo = i;
                    while (foo > 0)
                    {
                        int bar = foo;
                        if (bar > buf.buffer.Length)
                        {
                            bar = buf.buffer.Length;
                        }
                        i = io.ins.read(buf.buffer, 0, bar);
                        if (i < 0)
                        {
                            goto BREAK;
                        }
                        int data_len = i;
                        dst.Write(buf.buffer, 0, data_len);

                        offset += data_len;
                        foo -= data_len;

                        if (monitor != null)
                        {
                            if (!monitor.count(data_len))
                            {
                                while (foo > 0)
                                {
                                    i = io.ins.read(buf.buffer,
                                                    0,
                                                    (buf.buffer.Length < foo ? buf.buffer.Length : foo));
//.........这里部分代码省略.........
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:101,代码来源:ChannelSftp.cs

示例8: _lstat

        private SftpATTRS _lstat(String path)
        {
            try
            {
                sendLSTAT(path.GetBytes());

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_ATTRS)
                {
                    if (type == SSH_FXP_STATUS)
                    {
                        int i = buf.getInt();
                        throwStatusError(buf, i);
                    }
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                SftpATTRS attr = SftpATTRS.getATTR(buf);
                return attr;
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:31,代码来源:ChannelSftp.cs

示例9: isRemoteDir

        private bool isRemoteDir(String path)
        {
            try
            {
                sendSTAT(path.GetBytes());

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_ATTRS)
                {
                    return false;
                }
                SftpATTRS attr = SftpATTRS.getATTR(buf);
                return attr.isDir();
            }
            catch (Exception) { }
            return false;
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:23,代码来源:ChannelSftp.cs

示例10: cd

        /*
        cd /tmp
        c->s REALPATH
        s->c NAME
        c->s STAT
        s->c ATTR
        */
        public void cd(String path)
        {
            try
            {
                path = remoteAbsolutePath(path);

                ArrayList v = glob_remote(path);
                if (v.Count != 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }
                path = (String)(v[0]);
                sendREALPATH(path.GetBytes());

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != 101 && type != 104)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                int i;
                if (type == 101)
                {
                    i = buf.getInt();
                    throwStatusError(buf, i);
                }
                i = buf.getInt();
                byte[] str = buf.getString();

                if (str != null && str[0] != '/')
                {
                    str = (cwd + "/" + new JavaString(str)).GetBytes();
                }
                str = buf.getString(); // logname
                i = buf.getInt(); // attrs

                String newpwd = new JavaString(str);
                SftpATTRS attr = GetPathAttributes(newpwd);

                if ((attr.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0)
                {
                    throw new SftpException(SSH_FX_FAILURE, "Can't change directory: " + path);
                }

                if (!attr.isDir())
                {
                    throw new SftpException(SSH_FX_FAILURE, "Can't change directory: " + path);
                }

                cwd = newpwd;
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:69,代码来源:ChannelSftp.cs

示例11: glob_remote

        private ArrayList glob_remote(String _path)
        {
            ArrayList v = new ArrayList();
            byte[] path = _path.GetBytes();
            if (!isPattern(path))
            {
                v.Add(Util.unquote(_path));
                return v;
            }
            int i = path.Length - 1;
            while (i >= 0)
            {
                if (path[i] == '/') break;
                i--;
            }
            if (i < 0)
            {
                v.Add(Util.unquote(_path));
                return v;
            }
            byte[] dir;
            if (i == 0)
            {
                dir = new byte[] { (byte)'/' };
            }
            else
            {
                dir = new byte[i];
                Array.Copy(path, 0, dir, 0, i);
            }
            byte[] pattern = new byte[path.Length - i - 1];
            Array.Copy(path, i + 1, pattern, 0, pattern.Length);

            sendOPENDIR(dir);

            Header _header = new Header();
            _header = header(buf, _header);
            int length = _header.length;
            int type = _header.type;
            buf.rewind();
            fill(buf.buffer, 0, length);

            if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
            {
                throw new SftpException(SSH_FX_FAILURE, "");
            }
            if (type == SSH_FXP_STATUS)
            {
                i = buf.getInt();
                throwStatusError(buf, i);
            }

            byte[] handle = buf.getString(); // filename

            while (true)
            {
                sendREADDIR(handle);
                _header = header(buf, _header);
                length = _header.length;
                type = _header.type;

                if (type != SSH_FXP_STATUS && type != SSH_FXP_NAME)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                if (type == SSH_FXP_STATUS)
                {
                    buf.rewind();
                    fill(buf.buffer, 0, length);
                    break;
                }

                buf.rewind();
                fill(buf.buffer, 0, 4);
                length -= 4;
                int count = buf.getInt();

                byte[] str;

                buf.reset();
                while (count > 0)
                {
                    if (length > 0)
                    {
                        buf.shift();
                        int j = (buf.buffer.Length > (buf.index + length)) ? length : (buf.buffer.Length - buf.index);
                        i = io.ins.read(buf.buffer, buf.index, j);
                        if (i <= 0) break;
                        buf.index += i;
                        length -= i;
                    }

                    byte[] filename = buf.getString();
                    //System.err.println("filename: "+new String(filename));
                    str = buf.getString();
                    SftpATTRS attrs = SftpATTRS.getATTR(buf);

                    if (Util.glob(pattern, filename))
                    {
                        v.Add(new JavaString(dir) + "/" + new JavaString(filename));
//.........这里部分代码省略.........
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:101,代码来源:ChannelSftp.cs

示例12: glob_local

        private ArrayList glob_local(String _path)
        {
            ArrayList v = new ArrayList();
            byte[] path = _path.GetBytes();
            int i = path.Length - 1;
            while (i >= 0)
            {
                if (path[i] == '*' || path[i] == '?') break;
                i--;
            }
            if (i < 0)
            {
                v.Add(_path);
                return v;
            }
            while (i >= 0)
            {
                if (path[i] == file_separatorc) break;
                i--;
            }
            if (i < 0)
            {
                v.Add(_path);
                return v;
            }
            byte[] dir;
            if (i == 0)
            {
                dir = new byte[] { (byte)file_separatorc };
            }
            else
            {
                dir = new byte[i];
                Array.Copy(path, 0, dir, 0, i);
            }
            byte[] pattern = new byte[path.Length - i - 1];
            Array.Copy(path, i + 1, pattern, 0, pattern.Length);

            try
            {
                String[] children = (new File(Encoding.Default.GetString(dir))).list();
                for (int j = 0; j < children.Length; j++)
                {
                    if (Util.glob(pattern, children[j].GetBytes()))
                    {
                        v.Add(Encoding.Default.GetString(dir) + file_separator + children[j]);
                    }
                }
            }
            catch (Exception) { }
            return v;
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:52,代码来源:ChannelSftp.cs

示例13: symlink

        public void symlink(String oldpath, String newpath)
        {
            if (server_version < 3)
            {
                throw new SftpException(SSH_FX_FAILURE, "The remote sshd is too old to support symlink operation.");
            }

            try
            {
                oldpath = remoteAbsolutePath(oldpath);
                newpath = remoteAbsolutePath(newpath);

                ArrayList v = glob_remote(oldpath);
                int vsize = v.Count;
                if (vsize != 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }
                oldpath = (String)(v[0]);

                if (isPattern(newpath))
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }

                newpath = Util.unquote(newpath);

                sendSYMLINK(oldpath.GetBytes(), newpath.GetBytes());

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_STATUS)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }

                int i = buf.getInt();
                if (i == SSH_FX_OK) return;
                throwStatusError(buf, i);
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:51,代码来源:ChannelSftp.cs

示例14: rmdir

        public void rmdir(String path)
        {
            try
            {
                path = remoteAbsolutePath(path);

                ArrayList v = glob_remote(path);
                int vsize = v.Count;
                Header _header = new Header();

                for (int j = 0; j < vsize; j++)
                {
                    path = (String)(v[j]);
                    sendRMDIR(path.GetBytes());

                    _header = header(buf, _header);
                    int length = _header.length;
                    int type = _header.type;
                    buf.rewind();
                    fill(buf.buffer, 0, length);

                    if (type != SSH_FXP_STATUS)
                    {
                        throw new SftpException(SSH_FX_FAILURE, "");
                    }

                    int i = buf.getInt();
                    if (i != SSH_FX_OK)
                    {
                        throwStatusError(buf, i);
                    }
                }
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:39,代码来源:ChannelSftp.cs

示例15: readlink

        public String readlink(String path)
        {
            try
            {
                path = remoteAbsolutePath(path);
                ArrayList v = glob_remote(path);
                if (v.Count != 1)
                {
                    throw new SftpException(SSH_FX_FAILURE, v.ToString());
                }
                path = (String)(v[0]);

                sendREADLINK(path.GetBytes());

                Header _header = new Header();
                _header = header(buf, _header);
                int length = _header.length;
                int type = _header.type;
                buf.rewind();
                fill(buf.buffer, 0, length);

                if (type != SSH_FXP_STATUS && type != SSH_FXP_NAME)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                int i;
                if (type == SSH_FXP_NAME)
                {
                    int count = buf.getInt(); // count
                    byte[] filename = null;
                    byte[] longname = null;
                    for (i = 0; i < count; i++)
                    {
                        filename = buf.getString();
                        longname = buf.getString();
                        SftpATTRS.getATTR(buf);
                    }
                    return new JavaString(filename);
                }

                i = buf.getInt();
                throwStatusError(buf, i);
            }
            catch (Exception e)
            {
                if (e is SftpException) throw (SftpException)e;
                throw new SftpException(SSH_FX_FAILURE, "");
            }
            return null;
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:50,代码来源:ChannelSftp.cs


注:本文中的String.GetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。