本文整理匯總了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();
}