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


Java FTPClient.retrieveFileStream方法代码示例

本文整理汇总了Java中org.apache.commons.net.ftp.FTPClient.retrieveFileStream方法的典型用法代码示例。如果您正苦于以下问题:Java FTPClient.retrieveFileStream方法的具体用法?Java FTPClient.retrieveFileStream怎么用?Java FTPClient.retrieveFileStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.net.ftp.FTPClient的用法示例。


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

示例1: open

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
@Override
public FSDataInputStream open(Path file, int bufferSize) throws IOException {
  FTPClient client = connect();
  Path workDir = new Path(client.printWorkingDirectory());
  Path absolute = makeAbsolute(workDir, file);
  FileStatus fileStat = getFileStatus(client, absolute);
  if (fileStat.isDirectory()) {
    disconnect(client);
    throw new FileNotFoundException("Path " + file + " is a directory.");
  }
  client.allocate(bufferSize);
  Path parent = absolute.getParent();
  // Change to parent directory on the
  // server. Only then can we read the
  // file
  // on the server by opening up an InputStream. As a side effect the working
  // directory on the server is changed to the parent directory of the file.
  // The FTP client connection is closed when close() is called on the
  // FSDataInputStream.
  client.changeWorkingDirectory(parent.toUri().getPath());
  InputStream is = client.retrieveFileStream(file.getName());
  FSDataInputStream fis = new FSDataInputStream(new FTPInputStream(is,
      client, statistics));
  if (!FTPReply.isPositivePreliminary(client.getReplyCode())) {
    // The ftpClient is an inconsistent state. Must close the stream
    // which in turn will logout and disconnect from FTP server
    fis.close();
    throw new IOException("Unable to open file: " + file + ", Aborting");
  }
  return fis;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:32,代码来源:FTPFileSystem.java

示例2: getInputStream

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
@Override
public InputStream getInputStream() throws AuthenticationException, SocketException, IOException {
    FTPClient ftp = null;
    if (mUri.getScheme().equals("ftps"))
        ftp = Session.getInstance().getNewFTPSClient(mUri, FTP.BINARY_FILE_TYPE);
    else
        ftp = Session.getInstance().getNewFTPClient(mUri, FTP.BINARY_FILE_TYPE);
    InputStream is = ftp.retrieveFileStream(mUri.getPath());
    return is;

}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:12,代码来源:FtpFileEditor.java

示例3: downloadFile

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
/**
 * @desc 根据文件名下载文件
 *
 * @author liuliang
 *
 * @param filename
 *            文件名
 * @return boolean下载结果
 */
public byte[] downloadFile(String filename) {
	FTPClient ftpClient = ftpConnManager.getFTPClient();
	if (null == ftpClient || !ftpClient.isConnected()) {
		log.error("根据文件名下载文件失败,获取ftpClient失败,filename:{}", filename);
		return null;
	}
	try {
		ftpClient.enterLocalPassiveMode();
		InputStream ins = ftpClient.retrieveFileStream(new String(filename.getBytes("UTF-8"), "iso-8859-1"));
		if (null == ins) {
			return null;
		}
		ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
		byte[] buff = new byte[100];
		int rc = 0;
		int value =100;
		while ((rc = ins.read(buff, 0, value)) > 0) {
			swapStream.write(buff, 0, rc);
		}
		byte[] fileByte = swapStream.toByteArray();
		// ftpClient.getReply();
		return fileByte;
	} catch (IOException e) {
		log.error("根据文件名下载文件异常,filename:{}", filename, e);
	} finally {
		disconnect(ftpClient);
	}
	return null;
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:39,代码来源:FtpUtils.java

示例4: getInputStream

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
@Override
public InputStream getInputStream(final String remoteFileName, final FlowFile flowFile) throws IOException {
    final FTPClient client = getClient(null);
    InputStream in = client.retrieveFileStream(remoteFileName);
    if (in == null) {
        throw new IOException(client.getReplyString());
    }
    return in;
}
 
开发者ID:clickha,项目名称:nifi-tools,代码行数:10,代码来源:FTPTransferV2.java

示例5: getMessage

import org.apache.commons.net.ftp.FTPClient; //导入方法依赖的package包/类
@Override
public String getMessage() throws IOException {
	String message = null;
	try 
	{
		FTPClient ftpClient = new FTPClient();
		ftpClient.connect(server, port);
		ftpClient.login(user, password);
		ftpClient.enterLocalPassiveMode();
		ftpClient.setFileType(2);

		String remoteFile1 = "/"+file;
		InputStream inputStream = ftpClient.retrieveFileStream(remoteFile1);
		message = StreamUtility.readStream(inputStream, "iso-8859-1");
	    Boolean success = ftpClient.completePendingCommand();
	    
		if (success) {
			System.out.println("File has been downloaded successfully.");
		}
		
		inputStream.close();
	}
	catch (IOException e)
	{
		/* SendMail mail = new SendMail();
	      try
	      {
	        mail.postMail(this.properties.getProperty("mail"), "TMC-Fehler", 
	          e.getStackTrace().toString(), "[email protected]", this.properties
	          .getProperty("smtpHost"), this.properties
	          .getProperty("smtpUser"), this.properties
	          .getProperty("smtpPort"));
	      }
	      catch (MessagingException e1)
	      {
	        e1.printStackTrace();
	      }
	      this.logger.debug("Error with FTP connection " + 
	        e.getLocalizedMessage(), e);
	      throw new DownloadException(
	        "Error while downloading file from FTP " + 
	        e.getLocalizedMessage(), e);
		 */
	}

	return message;
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:48,代码来源:FtpDataSource.java


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