summaryrefslogtreecommitdiffstats
path: root/Dozentenmodul/src/main/java/ftp/FTPUtility.java
diff options
context:
space:
mode:
authorJonathan Bauer2014-09-10 14:54:40 +0200
committerJonathan Bauer2014-09-10 14:54:40 +0200
commit61e8e600dd1c9d6066711dfb9874e0117b87baf6 (patch)
treec5321291edcc9286fbe75f1cbf1a0548fb78da1d /Dozentenmodul/src/main/java/ftp/FTPUtility.java
parentMerge branch 'maven' of git.openslx.org:openslx-ng/tutor-module into maven (diff)
downloadtutor-module-61e8e600dd1c9d6066711dfb9874e0117b87baf6.tar.gz
tutor-module-61e8e600dd1c9d6066711dfb9874e0117b87baf6.tar.xz
tutor-module-61e8e600dd1c9d6066711dfb9874e0117b87baf6.zip
mavenization v2
Diffstat (limited to 'Dozentenmodul/src/main/java/ftp/FTPUtility.java')
-rw-r--r--Dozentenmodul/src/main/java/ftp/FTPUtility.java86
1 files changed, 42 insertions, 44 deletions
diff --git a/Dozentenmodul/src/main/java/ftp/FTPUtility.java b/Dozentenmodul/src/main/java/ftp/FTPUtility.java
index f2c51dfc..beae3f34 100644
--- a/Dozentenmodul/src/main/java/ftp/FTPUtility.java
+++ b/Dozentenmodul/src/main/java/ftp/FTPUtility.java
@@ -16,7 +16,6 @@ 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.
@@ -49,7 +48,7 @@ public class FTPUtility {
* Connect and login to the server.
*
* @throws FTPException
- * @throws NoSuchAlgorithmException
+ * @throws NoSuchAlgorithmException
*/
public void connect() throws FTPException, NoSuchAlgorithmException {
try {
@@ -58,8 +57,7 @@ public class FTPUtility {
if (!FTPReply.isPositiveCompletion(replyCode)) {
throw new FTPException("FTP serve refused connection.");
}
-
-
+
boolean logged = ftpClient.login(username, password);
if (!logged) {
// failed to login
@@ -122,43 +120,45 @@ public class FTPUtility {
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(Image.image.getNewName());
-
- //ftpClient.rename(uploadFile.getName(), );
- } 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);
- }
+
+ /**
+ * 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(Image.image.getNewName());
+
+ // ftpClient.rename(uploadFile.getName(), );
+ } 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.
@@ -191,11 +191,9 @@ public class FTPUtility {
public InputStream getInputStream() {
return inputStream;
}
-
+
public OutputStream getOutputStream() {
return outputStream;
}
-
-
} \ No newline at end of file