本文整理匯總了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;
}