本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}