本文整理汇总了Java中com.jcraft.jsch.Channel.start方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.start方法的具体用法?Java Channel.start怎么用?Java Channel.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcraft.jsch.Channel
的用法示例。
在下文中一共展示了Channel.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendFile
import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
private void sendFile(Channel channel, String localFile, String remoteName, String mode)
throws IOException, RemoteScpException {
byte[] buffer = new byte[BUFFER_SIZE];
OutputStream os = new BufferedOutputStream(channel.getOutputStream(),
SEND_FILE_BUFFER_LENGTH);
InputStream is = new BufferedInputStream(channel.getInputStream(), SEND_BYTES_BUFFER_LENGTH);
try {
if (channel.isConnected()) {
channel.start();
} else {
channel.connect();
}
} catch (JSchException jsche) {
throw new IOException("Channel connection problems", jsche);
}
readResponse(is);
File f = new File(localFile);
long remain = f.length();
String cMode = mode;
if (cMode == null) {
cMode = "0600";
}
String cline = "C" + cMode + " " + remain + " " + remoteName + "\n";
os.write(cline.getBytes());
os.flush();
readResponse(is);
try (FileInputStream fis = new FileInputStream(f)) {
while (remain > 0) {
int trans;
if (remain > buffer.length) {
trans = buffer.length;
} else {
trans = (int) remain;
}
if (fis.read(buffer, 0, trans) != trans) {
throw new IOException("Cannot read enough from local file " + localFile);
}
os.write(buffer, 0, trans);
remain -= trans;
}
fis.close();
}
os.write(0);
os.flush();
readResponse(is);
os.write("E\n".getBytes());
os.flush();
}