本文整理匯總了C#中Tamir.SharpSsh.jsch.Session.getHost方法的典型用法代碼示例。如果您正苦於以下問題:C# Session.getHost方法的具體用法?C# Session.getHost怎麽用?C# Session.getHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tamir.SharpSsh.jsch.Session
的用法示例。
在下文中一共展示了Session.getHost方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ScpWebResponse
//.........這裏部分代碼省略.........
throw new WebException("Username and password information for sourceforge.net incomplete");
}
session = jsch.getSession(userPass[0], "frs.sourceforge.net", 22);
// username and password will be given via UserInfo interface.
//UserInfo ui = new UserInfo();
//session.setUserInfo(ui);
session.setPassword(userPass[1]);
Hashtable hastable = new Hashtable();
hastable.put("StrictHostKeyChecking", "no");
session.setConfig(hastable);
if (DbManager.Proxy != null)
{
session.setProxy(new ProxyHTTP(DbManager.Proxy.Address.Host, DbManager.Proxy.Address.Port));
}
try
{
session.connect(timeout);
}
catch (JSchException e)
{
if (e.Message == "Auth fail")
{
throw new WebException("Invalid username or password for sourceforge");
}
throw;
}
// exec 'scp -f rfile' remotely
string sfPath = GetSourceforgePath(uri.LocalPath);
// Determine file modified date
ChannelSftp channelSftp = (ChannelSftp)session.openChannel("sftp");
channelSftp.connect();
try
{
SftpATTRS attrs = channelSftp.lstat(sfPath);
this.lastModified = RpcApplication.UnixToDotNet(attrs.getMTime());
}
catch (SftpException)
{
throw new WebException("The file \"" + sfPath + "\" could not be found.");
}
finally
{
channelSftp.disconnect();
}
String command = "scp -f " + sfPath.Replace(" ", "\\ ");
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
// get I/O streams for remote scp
Stream outs = channel.getOutputStream();
Stream ins = channel.getInputStream();
channel.connect();
byte[] buf = new byte[1024];
// send '\0'
buf[0] = 0; outs.Write(buf, 0, 1); outs.Flush();
int c = checkAck(ins);
if (c != 'C')
{
return;
}
// read '0644 '
ins.Read(buf, 0, 5);
while (true)
{
ins.Read(buf, 0, 1);
if (buf[0] == ' ') break;
this.contentLength = this.contentLength * 10 + (buf[0] - '0');
}
String file = null;
for (int i = 0; ; i++)
{
ins.Read(buf, i, 1);
if (buf[i] == (byte)0x0a)
{
file = Util.getString(buf, 0, i);
break;
}
}
this.responseUri = new Uri("scp://" + session.getHost() + sfPath);
// send '\0'
buf[0] = 0; outs.Write(buf, 0, 1); outs.Flush();
this.responseStream = ins;
}