need help with 'org.apache.commons.net.ftp.FTPClient'
I have this code which uploads to my ftp server fine however i am unable to return a value of how far the file has uploaded, any help would be appreciated thanks.
code:
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.SocketException;
public class FileUpload {
public FileUpload()
{
}
public static void main(String[] args) {
FTPClient ftp = new FTPClient();
try {
ftp.connect("localhost");
ftp.login("user","pass");
int reply = ftp.getReplyCode();
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Connected Success");
}else {
System.out.println("Connection Failed");
ftp.disconnect();
}
FileInputStream in = null;
try {
in = new FileInputStream("/home/matt/Desktop/testfile.txt");
ftp.storeFile("/home/matt/testfile.txt",in);
ftp.disconnect();
}catch(IOException e){
System.out.println(e);
}
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Re: need help with 'org.apache.commons.net.ftp.FTPClient'
If you're using any sort of GUI you can use the ProgressMonitorInputStream i am thinking to display how much of the file has been uploaded. Hopefully that helps or try to make the question little more clear for me to understand. how big is the file and all that good stuff.
--- Update ---
If i understand what you are asking for you can use this line to do it:
boolean done = ftpClient.storeFile(fileName, inputStream);
inputStream.close();
if (done) {
System.out.println("The first file is uploaded successfully.");
}
Let me know if that works.