Im using commons FTPCLIENT I just want the file content from the ftp server. i dont want to write it to a temporary file. Is there any way to do that. The fileoutputstream should always point to a local file.
Thanks in advance.
Im using commons FTPCLIENT I just want the file content from the ftp server. i dont want to write it to a temporary file. Is there any way to do that. The fileoutputstream should always point to a local file.
Thanks in advance.
Use FTPClient.retrieveFileStream(String)
.
You should use retrieveFilestream method instead of retriveFile method..
FTPClient ftp = new FTPClient();
// configuration code for ftpclient port, server etc
InputStream in = ftp.getretrieveFileStream("remoteFileName");
BufferedInputStream inbf = new BufferedInputStream(in);
byte buffer[] = new byte[1024];
int readCount;
byte result[] = null;
int length = 0;
while( (readCount = inbf.read(buffer)) > 0) {
int preLength = length;
length += readCount;
byte temp[] = new byte[result.length];
result = new byte[length];
System.arraycopy(temp,0,result,0,temp.length);
System.arraycopy(buffer,0,result,preLength,readCount);
}
return result;
Thanks a lot for the quick reply..
And that did work for me.. this is what i tried .
-
FTPclient fClient=new FTPclient();
fClient.connect("server");
Fclient.login("user","pwd");
InputStream iStream=fClient.retrieveFileStream("file");
BufferedInputStream bInf=new BufferedInputStream (iStream);
int bytesRead;
byte[] buffer=new byte[1024];
String fileContent=null;
while((bytesRead=bInf.read(buffer))!=-1)
{
fileContent=new String(buffer,0,bytesRead); }
enter code here