本文整理汇总了C#中Tamir.SharpSsh.java.String.getBytes方法的典型用法代码示例。如果您正苦于以下问题:C# String.getBytes方法的具体用法?C# String.getBytes怎么用?C# String.getBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tamir.SharpSsh.java.String
的用法示例。
在下文中一共展示了String.getBytes方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setClientVersion
public void setClientVersion(String cv)
{
V_C=cv.getBytes();
}
示例2: _stat
private SftpATTRS _stat(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)
{
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, "");
}
//return null;
}
示例3: cd
/*
cd /tmp
c->s REALPATH
s->c NAME
c->s STAT
s->c ATTR
*/
public void cd(String path)
{
//throws SftpException{
try
{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
if(v.size()!=1)
{
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
path=(String)(v.elementAt(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 String(str)).getBytes();
}
str=buf.getString(); // logname
i=buf.getInt(); // attrs
String newpwd=new String(str);
SftpATTRS attr=_stat(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, "");
}
}
示例4: glob_local
private Vector glob_local(String _path)
{ //throws Exception{
//System.out.println("glob_local: "+_path);
Vector v=new Vector();
byte[] path=_path.getBytes();
int i=path.Length-1;
while(i>=0){if(path[i]=='*' || path[i]=='?')break;i--;}
if(i<0){ v.addElement(_path); return v;}
while(i>=0){if(path[i]==file_separatorc)break;i--;}
if(i<0){ v.addElement(_path); return v;}
byte[] dir;
if(i==0){dir=new byte[]{(byte)file_separatorc};}
else
{
dir=new byte[i];
Tamir.SharpSsh.java.System.arraycopy(path, 0, dir, 0, i);
}
byte[] pattern=new byte[path.Length-i-1];
Tamir.SharpSsh.java.System.arraycopy(path, i+1, pattern, 0, pattern.Length);
//System.out.println("dir: "+new String(dir)+" pattern: "+new String(pattern));
try
{
String[] children=(new File(new String(dir))).list();
for(int j=0; j<children.Length; j++)
{
//System.out.println("children: "+children[j]);
if(Util.glob(pattern, children[j].getBytes()))
{
v.addElement(new String(dir)+file_separator+children[j]);
}
}
}
catch(Exception e)
{
}
return v;
}
示例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=_stat(dst);
skip=attr.getSize();
}
catch(Exception eee)
{
//System.err.println(eee);
}
}
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;
//.........这里部分代码省略.........
示例6: _setStat
private void _setStat(String path, SftpATTRS attr)
{
//throws SftpException{
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, "");
}
}
示例7: glob_remote
private Vector glob_remote(String _path)
{
//throws Exception{
//System.err.println("glob_remote: "+_path);
Vector v=new Vector();
byte[] path=_path.getBytes();
if(!isPattern(path))
{
v.addElement(Util.unquote(_path)); return v;
}
int i=path.Length-1;
while(i>=0){if(path[i]=='/')break;i--;}
if(i<0){ v.addElement(Util.unquote(_path)); return v;}
byte[] dir;
if(i==0){dir=new byte[]{(byte)'/'};}
else
{
dir=new byte[i];
java.System.arraycopy(path, 0, dir, 0, i);
}
//System.err.println("dir: "+new String(dir));
byte[] pattern=new byte[path.Length-i-1];
java.System.arraycopy(path, i+1, pattern, 0, pattern.Length);
//System.err.println("file: "+new String(pattern));
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;
int flags;
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.addElement(new String(dir)+"/"+new String(filename));
}
count--;
}
}
if(_sendCLOSE(handle, _header))
return v;
return null;
}
示例8: rmdir
public void rmdir(String path)
{
//throws SftpException{
try
{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
int vsize=v.size();
Header _header=new Header();
for(int j=0; j<vsize; j++)
{
path=(String)(v.elementAt(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, "");
}
}
示例9: mkdir
public void mkdir(String path)
{
//throws SftpException{
try
{
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);
}
catch(Exception e)
{
if(e is SftpException) throw (SftpException)e;
throw new SftpException(SSH_FX_FAILURE, "");
}
}
示例10: 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 e){}
return false;
}
示例11: rename
public void rename(String oldpath, String newpath)
{
//throws SftpException{
if(server_version<2)
{
throw new SftpException(SSH_FX_FAILURE,
"The remote sshd is too old to support rename operation.");
}
try
{
oldpath=remoteAbsolutePath(oldpath);
newpath=remoteAbsolutePath(newpath);
Vector v=glob_remote(oldpath);
int vsize=v.size();
if(vsize!=1)
{
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
oldpath=(String)(v.elementAt(0));
v=glob_remote(newpath);
vsize=v.size();
if(vsize>=2)
{
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
if(vsize==1)
{
newpath=(String)(v.elementAt(0));
}
else
{ // vsize==0
if(isPattern(newpath))
throw new SftpException(SSH_FX_FAILURE, newpath);
newpath=Util.unquote(newpath);
}
sendRENAME(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, "");
}
}
示例12: readlink
public String readlink(String path)
{
// throws SftpException{
try
{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
if(v.size()!=1)
{
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
path=(String)(v.elementAt(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 String(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;
}
示例13: get
public InputStream get(String src, SftpProgressMonitor monitor, int mode)
{ //throws SftpException{
if(mode==RESUME)
{
throw new SftpException(SSH_FX_FAILURE, "faile to resume from "+src);
}
src=remoteAbsolutePath(src);
try
{
Vector v=glob_remote(src);
if(v.size()!=1)
{
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
src=(String)(v.elementAt(0));
SftpATTRS attr=_stat(src);
if(monitor!=null)
{
monitor.init(SftpProgressMonitor.GET, src, "??", attr.getSize());
}
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, "");
}
if(type==SSH_FXP_STATUS)
{
int i=buf.getInt();
throwStatusError(buf, i);
}
byte[] handle=buf.getString(); // filename
java.io.InputStream ins=new InputStreamGet(this, handle, monitor);
// long offset=0;
// bool closed=false;
// int rest_length=0;
// byte[] _data=new byte[1];
// public int read() { //throws java.io.IOException{
// int i=read(_data, 0, 1);
// if (i==-1) { return -1; }
// else {
// return _data[0]&0xff;
// }
// }
// public int read(byte[] d) { //throws java.io.IOException{
// return read(d, 0, d.Length);
// }
// public int read(byte[] d, int s, int len) { //throws java.io.IOException{
// if(d==null){throw new NullPointerException();}
// if(s<0 || len <0 || s+len>d.Length){
// throw new IndexOutOfBoundsException();
// }
// if(len==0){ return 0; }
// if(rest_length>0){
// int foo=rest_length;
// if(foo>len) foo=len;
// int i=io.ins.read(d, s, foo);
// if(i<0){
// throw new IOException("error");
// }
// rest_length-=i;
// return i;
// }
// if(buf.buffer.Length-13<len){
// len=buf.buffer.Length-13;
// }
// if(server_version==0 && len>1024){
// len=1024;
// }
// try{sendREAD(handle, offset, len);}
// catch(Exception e){ throw new IOException("error"); }
// buf.rewind();
// int i=io.ins.read(buf.buffer, 0, 13); // 4 + 1 + 4 + 4
// if(i!=13){
// throw new IOException("error");
// }
// rest_length=buf.getInt();
// int type=buf.getByte();
// rest_length--;
// buf.getInt();
// rest_length-=4;
// if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){
// throw new IOException("error");
// }
//.........这里部分代码省略.........
示例14: _get
///tamir: updated to jcsh-0.1.30
private void _get(String src, OutputStream dst,
SftpProgressMonitor monitor, int mode, long skip)
{ //throws SftpException{
//System.out.println("_get: "+src+", "+dst);
//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)
{
//System.Console.WriteLine("Type is "+type);
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;
loop:
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,
//.........这里部分代码省略.........