Browse Source

Skeleton code with basic FTP(S) functionality

nolocaltime
Mendhak 10 years ago
parent
commit
d61b3dae69
  1. 13
      .idea/compiler.xml
  2. 13
      GPSLogger/GPSLogger.iml
  3. 5
      GPSLogger/pom.xml
  4. 97
      GPSLogger/src/com/mendhak/gpslogger/senders/ftp/FtpHelper.java
  5. 5
      pom.xml

13
.idea/compiler.xml

@ -28,10 +28,17 @@
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
<profile default="false" name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="GPSLogger" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_STRING" value="-target 1.6" />
<bytecodeTargetLevel>
<module name="GPSLogger" target="1.6" />
</bytecodeTargetLevel>
</component>
</project>

13
GPSLogger/GPSLogger.iml

@ -9,8 +9,6 @@
<option name="RES_FOLDER_RELATIVE_PATH" value="/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/assets" />
<option name="LIBS_FOLDER_RELATIVE_PATH" value="/libs" />
<option name="REGENERATE_R_JAVA" value="true" />
<option name="REGENERATE_JAVA_BY_AIDL" value="true" />
<option name="USE_CUSTOM_APK_RESOURCE_FOLDER" value="false" />
<option name="CUSTOM_APK_RESOURCE_FOLDER" value="" />
<option name="USE_CUSTOM_COMPILER_MANIFEST" value="false" />
@ -39,20 +37,14 @@
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/combined-assets" />
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/combined-resources" />
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/extracted-dependencies" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.android:android:2.3.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpclient:4.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpcore:4.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.khronos:opengl-api:gl1.1-android-2.1_r1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: xerces:xmlParserAPIs:2.6.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: xpp3:xpp3:1.1.4c" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.json:json:20080701" level="project" />
<orderEntry type="library" name="Maven: system.local:additionnal:1.0" level="project" />
<orderEntry type="library" name="Maven: system.local:activation:1.0" level="project" />
<orderEntry type="library" name="Maven: system.local:mail:1.0" level="project" />
@ -63,6 +55,7 @@
<orderEntry type="library" name="Maven: oauth.signpost:signpost-commonshttp4:1.2.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.james:apache-mime4j:0.6.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.0.3" level="project" />
<orderEntry type="library" name="Maven: commons-net:commons-net:2.x" level="project" />
<orderEntry type="inheritedJdk" />
</component>
</module>

5
GPSLogger/pom.xml

@ -130,6 +130,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>2.x</version>
</dependency>
</dependencies>

97
GPSLogger/src/com/mendhak/gpslogger/senders/ftp/FtpHelper.java

@ -18,9 +18,16 @@
package com.mendhak.gpslogger.senders.ftp;
import android.util.Log;
import com.mendhak.gpslogger.senders.IFileSender;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPSClient;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class FtpHelper implements IFileSender
@ -38,3 +45,93 @@ public class FtpHelper implements IFileSender
return false; //To change body of implemented methods use File | Settings | File Templates.
}
}
class TestFtpHandler implements Runnable
{
@Override
public void run()
{
boolean useFtps = false;
FTPClient client = null;
String protocol = "SSL";
//If implicit = true, set port to 990. If false, set to 21. If useFtps = false, set to 21.
boolean implicit = true;
int port = 990;
try
{
Log.v("FTPTEST", "Connecting...");
if(useFtps)
{
client = new FTPSClient(protocol, implicit);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(null, null);
KeyManager km = kmf.getKeyManagers()[0];
((FTPSClient) client).setKeyManager(km);
}
else
{
client = new FTPClient();
}
}
catch (Exception e)
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
client.connect("ftp.secureftp-test.com", port);
//
// When login success the login method returns true.
//
if (client.login("test", "test"))
{
Log.v("FTPTEST", "logged in");
client.enterLocalPassiveMode();
String data = "test data";
ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes());
// boolean result = client.storeFile("test2.txt", in);
// in.close();
// if (result)
// {
// Log.v("FTPTEST", "succeeded in writing file");
// }
// else
// {
// Log.v("FTPTEST", "failed to write file");
// }
}
else
{
Log.e("FTPTEST", "Login fail...");
}
} catch (IOException e) {
Log.e("FTPTEST", e.getMessage());
e.printStackTrace();
} finally {
try {
//
// Closes the connection to the FTP server
//
Log.v("FTPTEST", "Logging out...");
client.logout();
Log.v("FTPTEST", "Disconnecting...");
client.disconnect();
} catch (IOException e) {
Log.e("FTPTEST", e.getMessage());
e.printStackTrace();
}
}
}
}

5
pom.xml

@ -22,6 +22,11 @@
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save