summaryrefslogtreecommitdiffstats
path: root/Dozentenmodul/src/downloader/FTPUtility.java
diff options
context:
space:
mode:
authorunknown2014-02-25 11:04:51 +0100
committerunknown2014-02-25 11:04:51 +0100
commit2a3ec0fbda66ed07adcdc968a9365096ecd54f40 (patch)
tree187af202e5a404a15c31f0915e73cb23bf5b7900 /Dozentenmodul/src/downloader/FTPUtility.java
parentProblem der herumspringenden Fenster entfernt (diff)
downloadtutor-module-2a3ec0fbda66ed07adcdc968a9365096ecd54f40.tar.gz
tutor-module-2a3ec0fbda66ed07adcdc968a9365096ecd54f40.tar.xz
tutor-module-2a3ec0fbda66ed07adcdc968a9365096ecd54f40.zip
Kommunikation von BwLehrpool Suite zu BwLehrpool Suite Server läuft nun über Thrift
Diffstat (limited to 'Dozentenmodul/src/downloader/FTPUtility.java')
-rw-r--r--Dozentenmodul/src/downloader/FTPUtility.java230
1 files changed, 0 insertions, 230 deletions
diff --git a/Dozentenmodul/src/downloader/FTPUtility.java b/Dozentenmodul/src/downloader/FTPUtility.java
deleted file mode 100644
index bc45e69f..00000000
--- a/Dozentenmodul/src/downloader/FTPUtility.java
+++ /dev/null
@@ -1,230 +0,0 @@
-package downloader;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.SocketException;
-import java.security.NoSuchAlgorithmException;
-import org.apache.commons.net.ftp.FTP;
-import org.apache.commons.net.ftp.FTPFile;
-import org.apache.commons.net.ftp.FTPReply;
-import org.apache.commons.net.ftp.FTPSClient;
-
-
-/**
- * A utility class that provides functionality for downloading files from a FTP
- * server.
- *
- * @author www.codejava.net
- *
- */
-public class FTPUtility {
-
- // FTP server information
- private String host;
- private int port;
- private String username;
- private String password;
-
- private FTPSClient ftpClient = new FTPSClient();
- private int replyCode;
-
- private InputStream inputStream;
- private OutputStream outputStream;
-
- public FTPUtility(String host, int port, String user, String pass) {
- this.host = host;
- this.port = port;
- this.username = user;
- this.password = pass;
- }
-
- /**
- * Connect and login to the server.
- *
- * @throws FTPException
- * @throws NoSuchAlgorithmException
- */
- public void connect() throws FTPException, NoSuchAlgorithmException {
- try {
- ftpClient.connect(host, port);
- replyCode = ftpClient.getReplyCode();
- if (!FTPReply.isPositiveCompletion(replyCode)) {
- throw new FTPException("FTP serve refused connection.");
- }
-
-
- boolean logged = ftpClient.login(username, password);
- if (!logged) {
- // failed to login
- ftpClient.execPROT("P");
- ftpClient.disconnect();
- throw new FTPException("Could not login to the server.");
- }
-
- ftpClient.enterLocalPassiveMode();
-
- } catch (IOException ex) {
- throw new FTPException("I/O error: " + ex.getMessage());
- }
- }
-
- /**
- * Gets size (in bytes) of the file on the server.
- *
- * @param filePath
- * Path of the file on server
- * @return file size in bytes
- * @throws FTPException
- */
- public long getFileSize(String filePath) throws FTPException {
- try {
- FTPFile file = ftpClient.mlistFile(filePath);
- if (file == null) {
- throw new FTPException("The file may not exist on the server!");
- }
- return file.getSize();
- } catch (IOException ex) {
- throw new FTPException("Could not determine size of the file: "
- + ex.getMessage());
- }
- }
-
- /**
- * Start downloading a file from the server
- *
- * @param downloadPath
- * Full path of the file on the server
- * @throws FTPException
- * if client-server communication error occurred
- */
- public void downloadFile(String downloadPath) throws FTPException {
- try {
-
- boolean success = ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
- if (!success) {
- throw new FTPException("Could not set binary file type.");
- }
-
- inputStream = ftpClient.retrieveFileStream(downloadPath);
-
- if (inputStream == null) {
- throw new FTPException(
- "Could not open input stream. The file may not exist on the server.");
- }
- } catch (IOException ex) {
- throw new FTPException("Error downloading file: " + ex.getMessage());
- }
- }
-
-
- /**
- * Start uploading a file to the server
- * @param uploadFile the file to be uploaded
- * @param destDir destination directory on the server
- * where the file is stored
- * @throws FTPException if client-server communication error occurred
- */
- public void uploadFile(File uploadFile, String destDir) throws FTPException {
- try {
- boolean success = ftpClient.changeWorkingDirectory(destDir);
- if (!success) {
- throw new FTPException("Could not change working directory to "
- + destDir + ". The directory may not exist.");
- }
-
- success = ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
- if (!success) {
- throw new FTPException("Could not set binary file type.");
- }
-
- outputStream = ftpClient.storeFileStream(uploadFile.getName());
- // ftpClient.rename(uploadFile.getName(), vm.vl.getLaborname());
- } catch (IOException ex) {
- throw new FTPException("Error uploading file: " + ex.getMessage());
- }
- }
-
- /**
- * Write an array of bytes to the output stream.
- */
- public void writeFileBytes(byte[] bytes, int offset, int length)
- throws IOException {
- outputStream.write(bytes, offset, length);
- }
-
- /**
- * Complete the download operation.
- */
- public void finish() throws IOException {
- inputStream.close();
- ftpClient.completePendingCommand();
- }
-
- /**
- * Log out and disconnect from the server
- */
- public void disconnect() throws FTPException {
- if (ftpClient.isConnected()) {
- try {
- if (!ftpClient.logout()) {
- throw new FTPException("Could not log out from the server");
- }
- ftpClient.disconnect();
- } catch (IOException ex) {
- throw new FTPException("Error disconnect from the server: "
- + ex.getMessage());
- }
- }
- }
-
- /**
- * Return InputStream of the remote file on the server.
- */
- public InputStream getInputStream() {
- return inputStream;
- }
-
- public OutputStream getOutputStream() {
- return outputStream;
- }
-
- public String[] getAllRohling(String SearchString) throws SocketException
- {
- //FTPClient ftp=new FTPClient();
-
- String[] filenamelist;
-
-
- try {
-
-
- ftpClient.changeWorkingDirectory("/home/openslx/images");
- filenamelist=ftpClient.listNames();
-
- String[] search=new String[filenamelist.length];
- for(int i=0;i<filenamelist.length;i++)
- {
- /*if(filenamelist[i].startsWith(SearchString)==true)
- {
- search[i]=filenamelist[i];
- }*/
-
- if(filenamelist[i].contains(SearchString)==true)
- {
- search[i]=filenamelist[i];
- }
- }
- return search;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
-
-
- return null;
- }
-
-} \ No newline at end of file