本文整理汇总了Java中com.jcraft.jsch.ChannelSftp.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelSftp.disconnect方法的具体用法?Java ChannelSftp.disconnect怎么用?Java ChannelSftp.disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jcraft.jsch.ChannelSftp
的用法示例。
在下文中一共展示了ChannelSftp.disconnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: upload
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
* Creates a new file on the remote host using the input content.
*
* @param from the byte array content to be uploaded
* @param fileName the name of the file for which the content will be saved into
* @param toPath the path of the file for which the content will be saved into
* @param isUserHomeBased true if the path of the file is relative to the user's home directory
* @param filePerm file permissions to be set
* @throws Exception exception thrown
*/
public void upload(InputStream from, String fileName, String toPath, boolean isUserHomeBased, String filePerm) throws Exception {
ChannelSftp channel = (ChannelSftp) this.session.openChannel("sftp");
channel.connect();
String absolutePath = isUserHomeBased ? channel.getHome() + "/" + toPath : toPath;
String path = "";
for (String dir : absolutePath.split("/")) {
path = path + "/" + dir;
try {
channel.mkdir(path);
} catch (Exception ee) {
}
}
channel.cd(absolutePath);
channel.put(from, fileName);
if (filePerm != null) {
channel.chmod(Integer.parseInt(filePerm), absolutePath + "/" + fileName);
}
channel.disconnect();
}
示例2: download
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
* Downloads the content of a file from the remote host as a String.
*
* @param fileName the name of the file for which the content will be downloaded
* @param fromPath the path of the file for which the content will be downloaded
* @param isUserHomeBased true if the path of the file is relative to the user's home directory
* @return the content of the file
* @throws Exception exception thrown
*/
public String download(String fileName, String fromPath, boolean isUserHomeBased) throws Exception {
ChannelSftp channel = (ChannelSftp) this.session.openChannel("sftp");
channel.connect();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BufferedOutputStream buff = new BufferedOutputStream(outputStream);
String absolutePath = isUserHomeBased ? channel.getHome() + "/" + fromPath : fromPath;
channel.cd(absolutePath);
channel.get(fileName, buff);
channel.disconnect();
return outputStream.toString();
}
示例3: ls
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public List<String> ls(String path)
throws FileBasedHelperException {
try {
List<String> list = new ArrayList<String>();
ChannelSftp channel = getSftpChannel();
Vector<LsEntry> vector = channel.ls(path);
for (LsEntry entry : vector) {
list.add(entry.getFilename());
}
channel.disconnect();
return list;
} catch (SftpException e) {
throw new FileBasedHelperException("Cannot execute ls command on sftp connection", e);
}
}
示例4: ls
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
public static List<String> ls(String hostname, int port, String username, File keyFile, final String passphrase,
String path) throws JSchException, IOException, SftpException {
Session session = createSession(hostname, port, username, keyFile, passphrase);
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
@SuppressWarnings("unchecked")
Vector<LsEntry> vector = (Vector<LsEntry>) channel.ls(path);
channel.disconnect();
session.disconnect();
List<String> files = new ArrayList<String>();
for (LsEntry lse : vector) {
files.add(lse.getFilename());
}
return files;
}
示例5: uploadFile
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
public static void uploadFile(String hostname, int port, String username, File keyFile, final String passphrase,
File file, String destinationFolder) throws JSchException, IOException, SftpException {
Session session = createSession(hostname, port, username, keyFile, passphrase);
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
channel.cd(destinationFolder);
channel.put(new FileInputStream(file), file.getName());
channel.disconnect();
session.disconnect();
}
示例6: _testConnectionSftp
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
private void _testConnectionSftp(String user, String password, String host, int port, IMoverInterface callbackContext) {
try {
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
OutputStream output = channel.put(mTestFilename);
output.write("Hello Alto".getBytes());
output.close();
channel.rm(mTestFilename);
channel.disconnect();
session.disconnect();
callbackContext.success();
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
示例7: put
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
public void put(Path localPath, String remotePath) throws JSchException, SftpException {
connectIfNot();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
try {
channel.connect();
logger.info("sftp put, from={}, to={}", localPath, remotePath);
channel.put(new ByteArrayInputStream(Files.bytes(localPath)), remotePath);
} finally {
channel.disconnect();
}
}
示例8: close
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public void close(boolean success) {
Session session = threadSession.get();
if (session != null) {
session.disconnect();
threadSession.set(null);
}
Map<Integer, ChannelSftp> channels = threadChannels.get();
if (channels != null) {
Iterator<Entry<Integer, ChannelSftp>> itr = channels.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<Integer, ChannelSftp> entry = itr.next();
ChannelSftp channel = entry.getValue();
if (channel != null) {
channel.disconnect();
}
}
channels.clear();
threadChannels.set(null);
}
}
示例9: doSingleTransfer
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
private void doSingleTransfer() throws IOException, JSchException {
final ChannelSftp channel = openSftpChannel();
try {
channel.connect();
try {
sendFileToRemote(channel, localFile, remotePath);
} catch (final SftpException e) {
throw new JSchException("Could not send '" + localFile
+ "' to '" + remotePath + "' - "
+ e.toString(), e);
}
} finally {
if (channel != null) {
channel.disconnect();
}
}
}
示例10: putChannel
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
* Returns a channel to the pool.
*/
protected void putChannel(final ChannelSftp channel)
{
if (idleChannel == null)
{
// put back the channel only if it is still connected
if (channel.isConnected() && !channel.isClosed())
{
idleChannel = channel;
}
}
else
{
channel.disconnect();
}
}
示例11: getFileMTime
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
@Override
public long getFileMTime(String filePath) throws FileBasedHelperException {
ChannelSftp channelSftp = null;
try {
channelSftp = getSftpChannel();
int modificationTime = channelSftp.lstat(filePath).getMTime();
return modificationTime;
} catch (SftpException e) {
throw new FileBasedHelperException(
String.format("Failed to get modified timestamp for file at path %s due to error %s", filePath,
e.getMessage()),
e);
} finally {
if (channelSftp != null) {
channelSftp.disconnect();
}
}
}
示例12: release
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
protected final void release(ChannelSftp ch) {
if (needsNewChannel) {
ch.disconnect();
} else {
// ignore as we want to reuse the channel
}
}
示例13: disconnect
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
void disconnect(ChannelSftp channel) throws IOException {
if (channel != null) {
// close connection if too many active connections
boolean closeConnection = false;
synchronized (this) {
if (liveConnectionCount > maxConnection) {
--liveConnectionCount;
con2infoMap.remove(channel);
closeConnection = true;
}
}
if (closeConnection) {
if (channel.isConnected()) {
try {
Session session = channel.getSession();
channel.disconnect();
session.disconnect();
} catch (JSchException e) {
throw new IOException(StringUtils.stringifyException(e));
}
}
} else {
returnToPool(channel);
}
}
}
示例14: lstat
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
* This method returns the file attributes of the remote file.
*
* @param session JSch session
* @param remoteFile Absolute path of the remote file
* @return SftpATTRS object that contains the file attributes
* @throws JSchException
* @throws SftpException
*/
public static SftpATTRS lstat( Session session, String remoteFile )
throws JSchException, SftpException
{
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel( "sftp" );
sftpChannel.connect();
SftpATTRS fileStat = sftpChannel.lstat( remoteFile );
sftpChannel.disconnect();
return fileStat;
}
示例15: lstat
import com.jcraft.jsch.ChannelSftp; //导入方法依赖的package包/类
/**
* This method returns the file attributes of the remote file.
*
* @param session JSch session
* @param remoteFile Absolute path of the remote file
* @return SftpATTRS object that contains the file attributes
* @throws JSchException
* @throws SftpException
*/
public static SftpATTRS lstat( Session session, String remoteFile )
throws JSchException, SftpException
{
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel( "sftp" );
sftpChannel.connect();
SftpATTRS fileStat = sftpChannel.lstat( remoteFile );
sftpChannel.disconnect();
return fileStat;
}