/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Copyright 2010 Joe Robinson */ package com.lc8n.blauploader; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.net.SocketException; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import android.os.Handler; public class FileUpload implements Runnable{ private File file; private Handler pbHandle; public FileUpload(File file, Handler pbHandle) { this.file = file; this.pbHandle = pbHandle; } public void uploadFile(File file, Handler pbHandle) throws SocketException, IOException { FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); ProgressInputStream pis = new ProgressInputStream(bis,pbHandle); String fileName = file.getName(); FTPClient ftpClient = new FTPClient(); ftpClient.connect("tghost.co.uk"); ftpClient.login("blaupload", "lemons"); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); ftpClient.changeWorkingDirectory("/"); ftpClient.storeFile(fileName, pis); bis.close(); pis.close(); ftpClient.logout(); ftpClient.disconnect(); } public void run() { try { uploadFile(file, pbHandle); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }