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


Java SftpException类代码示例

本文整理汇总了Java中com.jcraft.jsch.SftpException的典型用法代码示例。如果您正苦于以下问题:Java SftpException类的具体用法?Java SftpException怎么用?Java SftpException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SftpException类属于com.jcraft.jsch包,在下文中一共展示了SftpException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: put

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
/**
 * Send a file to server path via SFTP
 * @param src
 * @param path
 * @throws SftpException
 */
public void put(final File src, String path) throws SftpException
{
    if (!path.endsWith("/")) path = path.concat("/");
    if (path.startsWith("/")) path = path.substring(1);
    
    ChannelSftp sftp = (ChannelSftp) channel;
    SftpProgressMonitor progress = new SftpProgressMonitor() {
        
        @Override public void init(int arg0, String arg1, String arg2, long arg3)
        {
            System.out.println("File transfer begin..");
        }
        
        @Override public void end()
        {
            Out.print(LOG_LEVEL.INFO, "Upload of file "+ src.getName() +" succeeded.");
            ready = true;
        }
        
        @Override public boolean count(long i) { return false; }
    };
    sftp.put(src.getAbsolutePath(), initRemDir+path+src.getName(), progress);
}
 
开发者ID:DevComPack,项目名称:setupmaker,代码行数:30,代码来源:JschFactory.java

示例2: getRemoteFileList

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Vector<LsEntry> getRemoteFileList(String user, String password, String addr, int port, String cwd) throws JSchException, 
	SftpException, Exception {
	
	Session session = getSession(user, password, addr, port);	
	Vector<LsEntry> lsVec=null;
	Channel channel = session.openChannel("sftp");
	channel.connect();
	ChannelSftp sftpChannel = (ChannelSftp) channel;
	try {
		lsVec=(Vector<LsEntry>)sftpChannel.ls(cwd); //sftpChannel.lpwd()
	} catch (Exception e) {
		e.printStackTrace();
		throw e;
	} finally {
		sftpChannel.exit();
		channel.disconnect();
		session.disconnect();			
	}		
	return lsVec;		
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:22,代码来源:SFtpClientUtils.java

示例3: createStatInfo

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
private StatInfo createStatInfo(String dirName, String baseName, SftpATTRS attrs, ChannelSftp cftp) throws SftpException {
    String linkTarget = null;
    if (attrs.isLink()) {
        String path = dirName + '/' + baseName;
        RemoteStatistics.ActivityID activityID = RemoteStatistics.startChannelActivity("readlink", path); // NOI18N
        try {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "performing readlink {0}", path);
            }
            linkTarget = cftp.readlink(path);
        } finally {
            RemoteStatistics.stopChannelActivity(activityID);
        }
    }
    Date lastModified = new Date(attrs.getMTime() * 1000L);
    StatInfo result = new FileInfoProvider.StatInfo(baseName, attrs.getUId(), attrs.getGId(), attrs.getSize(),
            attrs.isDir(), attrs.isLink(), linkTarget, attrs.getPermissions(), lastModified);
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:SftpSupport.java

示例4: listFiles

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
public synchronized List<ChannelSftp.LsEntry> listFiles(String path) throws GenericFileOperationFailedException {
    LOG.trace("listFiles({})", path);
    if (ObjectHelper.isEmpty(path)) {
        // list current directory if file path is not given
        path = ".";
    }

    try {
        final List<ChannelSftp.LsEntry> list = new ArrayList<ChannelSftp.LsEntry>();

        @SuppressWarnings("rawtypes")
        Vector files = channel.ls(path);
        // can return either null or an empty list depending on FTP servers
        if (files != null) {
            for (Object file : files) {
                list.add((ChannelSftp.LsEntry) file);
            }
        }
        return list;
    } catch (SftpException e) {
        throw new GenericFileOperationFailedException("Cannot list directory: " + path, e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:SftpOperations.java

示例5: listEntries

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
private Vector<LsEntry> listEntries(final ChannelSftp channelSftp, final String path) throws SftpException {
    final Vector<LsEntry> vector = new Vector<LsEntry>();

    LsEntrySelector selector = new LsEntrySelector() {
        public int select(LsEntry entry)  {
            final String filename = entry.getFilename();
            if (filename.equals(".") || filename.equals("..")) {
                return CONTINUE;
            }
            if (entry.getAttrs().isLink()) {
                vector.addElement(entry);
            }
            else if (entry.getAttrs().isDir()) {
                if (keepDirectory(filename)) {
                    vector.addElement(entry);
                }
            }
            else {
                 if (keepFile(filename)) {
                    vector.addElement(entry);
                }
            }
            return CONTINUE;
        }
    };

    channelSftp.ls(path, selector);
    return vector;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:30,代码来源:SFtpListingEngine.java

示例6: openSftpChannel

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
/**
 * Opens a new SFTP channel over this SSH session.
 *
 * @throws JSchException
 * @throws SftpException
 * @see JSchSftpChannel
 */
public JSchSftpChannel openSftpChannel() throws JSchException, SftpException {
  ChannelSftp chan = (ChannelSftp) session.openChannel("sftp");
  chan.connect(timeout);
  if (url.getPath().isPresent()) {
    String dir = url.getPath().get();
    try {
      chan.cd(dir);
    } catch (SftpException e) {
      logger.warning(e.toString());
      mkdirs(chan, dir);
      chan.cd(dir);
    }
  }
  return new JSchSftpChannel(chan);
}
 
开发者ID:google,项目名称:nomulus,代码行数:23,代码来源:JSchSshSession.java

示例7: rename

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
/**
   * 文件重命名
   * @param oldpath
   * @param newpath
   * @return boolean
   */
  public  boolean rename(String oldpath,String newpath) {
	boolean flag=false;
	ChannelSftp channel=getChannel();
	try {
		channel.rename(oldpath, newpath);
		log.info("重命名文件"+oldpath+"成功");
		log.info("更新后的文件名为:"+newpath);
		flag=true;
	} catch (SftpException e) {
		log.error("重命名文件"+oldpath+"失败");
		log.error(e.getMessage());
	}finally {
		//channel.quit();
         
      }
	
	return flag;
}
 
开发者ID:sapientTest,项目名称:Sapient,代码行数:25,代码来源:SftpFileUtil.java

示例8: work

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
protected void work() throws IOException, CancellationException, JSchException, SftpException, ExecutionException, InterruptedException {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} started", getTraceName());
    }
    ChannelSftp cftp = getChannel();
    RemoteStatistics.ActivityID activityID = RemoteStatistics.startChannelActivity("download", srcFileName); // NOI18N
    try {
        cftp.get(srcFileName, dstFileName);
    } catch (SftpException e) {
        if (MiscUtils.mightBrokeSftpChannel(e)) {
            cftp.quit();
        }
        throw decorateSftpException(e, srcFileName);
    } finally {
        releaseChannel(cftp);
        RemoteStatistics.stopChannelActivity(activityID, new File(dstFileName).length());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SftpSupport.java

示例9: call

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
@Override
public StatInfo call() throws Exception {
    StatInfo result = null;
    SftpException exception = null;
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} started", getTraceName());
    }
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(PREFIX + ": " + getTraceName()); // NOI18N
    RemoteStatistics.ActivityID activityID = RemoteStatistics.startChannelActivity("move", from); // NOI18N
    ChannelSftp cftp = null;
    try {
        cftp = getChannel();
        cftp.rename(from, to);
    } catch (SftpException e) {
        exception = e;
        if (e.id == SftpIOException.SSH_FX_FAILURE) {
            if (MiscUtils.mightBrokeSftpChannel(e)) {
                cftp.quit();
            }
        }
    } finally {
        RemoteStatistics.stopChannelActivity(activityID);
        releaseChannel(cftp);
        Thread.currentThread().setName(threadName);
    }
    if (exception != null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, "{0} failed", getTraceName());
        }
        throw decorateSftpException(exception, from + " to " + to); //NOI18N
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} finished", new Object[] {getTraceName()});
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:SftpSupport.java

示例10: testJschConnection

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
@Test
public void testJschConnection() throws InterruptedException, SftpException, JSchException, IOException {
    JSch jsch = new JSch();
    String passphrase = "";
    jsch.addIdentity(privateKey,
        StringUtil.isEmpty(passphrase) ?
        null : passphrase);

    Session session = jsch.getSession(user, host, port);
    System.out.println("session created.");

    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    config.put("PreferredAuthentications",
        "publickey,keyboard-interactive,password");
    session.setConfig(config);
    session.connect();
    Thread.sleep(500);
    session.disconnect();
}
 
开发者ID:sanchouss,项目名称:InstantPatchIdeaPlugin,代码行数:21,代码来源:RemoteClientImplTest.java

示例11: buildDirectoryChunks

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
private boolean buildDirectoryChunks(String dirName) throws IOException, SftpException {
    final StringBuilder sb = new StringBuilder(dirName.length());
    final String[] dirs = dirName.split("/|\\\\");

    boolean success = false;
    for (String dir : dirs) {
        sb.append(dir).append('/');
        // must normalize the directory name
        String directory = endpoint.getConfiguration().normalizePath(sb.toString());

        // do not try to build root folder (/ or \)
        if (!(directory.equals("/") || directory.equals("\\"))) {
            try {
                LOG.trace("Trying to build remote directory by chunk: {}", directory);

                channel.mkdir(directory);
                success = true;
            } catch (SftpException e) {
                // ignore keep trying to create the rest of the path
            }
        }
    }

    return success;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:SftpOperations.java

示例12: put

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
/**
 * 本地檔案放到遠端SFTP上
 * 	
 * @param user
 * @param password
 * @param addr
 * @param port
 * @param localFile
 * @param remoteFile
 * @throws JSchException
 * @throws SftpException
 * @throws Exception
 */
public static void put(String user, String password, String addr, int port,
		List<String> localFile, List<String> remoteFile) throws JSchException, SftpException, Exception {
	
	Session session = getSession(user, password, addr, port);	
	Channel channel = session.openChannel("sftp");
	channel.connect();
	ChannelSftp sftpChannel = (ChannelSftp) channel;		
	try {
		for (int i=0; i<localFile.size(); i++) {
			String rf=remoteFile.get(i);
			String lf=localFile.get(i);
			logger.info("put local file: " + lf + " write to " + addr + " :" + rf );
			sftpChannel.put(lf, rf);
			logger.info("success write to " + addr + " :" + rf);
		}
	} catch (Exception e) {
		e.printStackTrace();
		throw e;
	} finally {
		sftpChannel.exit();
		channel.disconnect();
		session.disconnect();				
	}		
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:38,代码来源:SFtpClientUtils.java

示例13: SshToolInvocation

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
public SshToolInvocation(ToolDescription desc, SshNode workerNodeA,
		AskUserForPw askUserForPwA, CredentialManager credentialManager)
		throws JSchException, SftpException {
	this.workerNode = workerNodeA;
	this.credentialManager = credentialManager;

	setRetrieveData(workerNodeA.isRetrieveData());
	this.askUserForPw = askUserForPwA;
	usecase = desc;

	ChannelSftp sftp = SshPool.getSftpPutChannel(workerNode, askUserForPw);
	synchronized (getNodeLock(workerNode)) {

		logger.info("Changing remote directory to "
				+ workerNode.getDirectory());
		sftp.cd(workerNode.getDirectory());
		Random rnd = new Random();
		while (true) {
			tmpname = "usecase" + rnd.nextLong();
			try {
				sftp.lstat(workerNode.getDirectory() + tmpname);
				continue;
			} catch (Exception e) {
				// file seems to not exist :)
			}
			sftp.mkdir(workerNode.getDirectory() + tmpname);
			sftp.cd(workerNode.getDirectory() + tmpname);
			break;
		}
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-common-activities,代码行数:32,代码来源:SshToolInvocation.java

示例14: ls

import com.jcraft.jsch.SftpException; //导入依赖的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

示例15: upload

import com.jcraft.jsch.SftpException; //导入依赖的package包/类
public static void upload(String directory, String uploadFile, ChannelSftp sftp) throws Exception{
	
	File file = new File(uploadFile);
	if(file.exists()){
		
		try {
			Vector content = sftp.ls(directory);
			if(content == null){
				sftp.mkdir(directory);
				System.out.println("mkdir:" + directory);
			}
		} catch (SftpException e) {
			sftp.mkdir(directory);
		}
		sftp.cd(directory);
		System.out.println("directory: " + directory);
		if(file.isFile()){
			InputStream ins = new FileInputStream(file);
			
			sftp.put(ins, new String(file.getName().getBytes(),"UTF-8"));
			
		}else{
			File[] files = file.listFiles();
			for (File file2 : files) {
				String dir = file2.getAbsolutePath();
				if(file2.isDirectory()){
					String str = dir.substring(dir.lastIndexOf(file2.separator));
					directory = directory + str;
				}
				System.out.println("directory is :" + directory);
				upload(directory,dir,sftp);
			}
		}
	}
}
 
开发者ID:zhuyuqing,项目名称:bestconf,代码行数:36,代码来源:SFTPUtil.java


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