当前位置: 首页>>代码示例>>Java>>正文


Java ChannelSftp.disconnect方法代码示例

本文整理汇总了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();
}
 
开发者ID:Azure-Samples,项目名称:acr-java-manage-azure-container-registry,代码行数:32,代码来源:SSHShell.java

示例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();
}
 
开发者ID:Azure-Samples,项目名称:acr-java-manage-azure-container-registry,代码行数:23,代码来源:SSHShell.java

示例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);
  }
}
 
开发者ID:Hanmourang,项目名称:Gobblin,代码行数:18,代码来源:SftpFsHelper.java

示例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;
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:17,代码来源:JSchUtil.java

示例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();
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:12,代码来源:JSchUtil.java

示例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());
    }
}
 
开发者ID:adamduren,项目名称:cordova-mover,代码行数:27,代码来源:BaseMover.java

示例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();
    }
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:12,代码来源:SSH.java

示例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);
    }
}
 
开发者ID:JumpMind,项目名称:metl,代码行数:22,代码来源:SftpDirectory.java

示例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();
        }
    }
}
 
开发者ID:apache,项目名称:ant,代码行数:18,代码来源:ScpToMessageBySftp.java

示例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();
    }
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:19,代码来源:SftpFileSystem.java

示例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();
 }
    }
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:19,代码来源:SftpFsHelper.java

示例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
    }
}
 
开发者ID:osglworks,项目名称:java-sftp,代码行数:8,代码来源:SftpCmd.java

示例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);
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:SFTPConnectionPool.java

示例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;
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:19,代码来源:SshUtil.java

示例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;
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:19,代码来源:SshUtil.java


注:本文中的com.jcraft.jsch.ChannelSftp.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。