Android Zugriff auf FTP-Server

Kratos

Mitglied
Ich entwickle zurzeit eine App, die unter Anderem auf meinen FTP-Server zugreifen soll.
Dazu verwende ich einen Sourcecode von einem früheren Projekt, allerdings ein Java Programm
und keine Android Application:

Der Sourcecode, hier wird einfach nur eine FTP datei ausgelesen, ein String draufgeklatscht und sie wieder hochgeladen:
Java:
try{
			
			URL url = new URL("ftp://*****;type=i");
			URLConnection urlc = url.openConnection();
			urlc = url.openConnection();
			
			InputStream is = urlc.getInputStream();
			InputStreamReader readerS = new InputStreamReader(is);
			BufferedReader r = new BufferedReader(readerS);
			
			String msg = null; 
			
			while((msg = r.readLine()) != null){
				actualText += msg + "\n";
			}
			
			readerS.close();
			r.close();
			is.close();
			urlc = null;
			
			url = new URL("ftp://u78111953:Ichbingut1!@senad-alic.com/python/abx.txt;type=i");
			urlc = url.openConnection();
			
			BufferedWriter wr=new BufferedWriter(new OutputStreamWriter(urlc.getOutputStream()));
			
			
			wr.write(uploadText + "\n\n\n" + actualText);
			wr.flush();
			wr.close();
			urlc = null;
			
			
			}catch(IOException e ){
			}

Mein App-Source Code, die "sendEditor" Methode geht los beim Drücken des Buttons auf meiner APP
Java:
//hier sind alle Importe

public class MainActivity extends ActionBarActivity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	public void sendEditor(View view) {
	    
	    EditText textf = (EditText) findViewById(R.id.editText);
	    Log.v("Ausgabe", ""+textf.getText());
	    try{
			String actualText = "";
			URL url = new URL("ftp://**********");
			URLConnection urlc = url.openConnection();
			urlc = url.openConnection();
			
			InputStream is = urlc.getInputStream();
			InputStreamReader readerS = new InputStreamReader(is);
			BufferedReader r = new BufferedReader(readerS);
			
			String msg = null; 
			
			while((msg = r.readLine()) != null){
				actualText += msg + "\n";
			}

			readerS.close();
			r.close();
			is.close();
			urlc = null;
			
			url = new URL("ftp://");
			urlc = url.openConnection();
			
			BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(urlc.getOutputStream()));
			
			DateFormat df=DateFormat.getDateInstance(DateFormat.MEDIUM);
			
			df=DateFormat.getTimeInstance(DateFormat.SHORT);
			
			String uploadText= ""+textf.getText();
			wr.write(uploadText + "\n\n\n" + actualText);
			wr.flush();
			wr.close();
			urlc = null;
			
			
			}catch(IOException e ){
				Log.v("Ausgabe", "Schon wieder eine dumme Exception!");
			}
		
			
	}
}
Hier die XML meines Layouts
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="de.python.duracal.MainActivity" >

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message"
        android:inputType="textMultiLine" >

    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="sendEditor"
        android:text="Editor" />

</LinearLayout>
Und hier sollte eigentlich alles in Ordnung sein, Rechte auf Internet gewährleistet
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.python.duracal"
    android:versionCode="1"
    android:versionName="1.0" >
	<uses-permission android:name="android.permission.INTERNET" /> 
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="20" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Die App bleibt bei
Java:
InputStream is = urlc.getInputStream();
hängen

Hat jemand Ansätze? 🙂

Ich finde es einfach nur seltsam, dass es bei einer normalen Java-App klappt aber nicht bei einer
für Android, trotz gleichen Sourcecodes....
 
Zuletzt bearbeitet:

Zurück
Oben