Datei Upload FTP

Matze82

Mitglied
Hallo,

nachdem ich mich durch viele Seiten gewühlt habe, aber noch zu keinem Ergebnis gekommen bin, nun meine Frage an euch.
Ich benötige eine Komponente zum Uploaden von Dateien auf einen FTP. :confused:

Bin für jede Info dankbar
 
Das Apache Commons Net hab ich schon mehrmals gelesen, das es am besten sein soll.
Aber ich bekomme es einfach net zum laufen. Verbindung geht, aber ein Upload t net :confused:

Gibts das Beispiel Code?
 
Mein Code sieht folgendermaßen aus:



String server = "";
String username = "";
String password = "";
String remote = "";
String local = "c:\\test.txt";

FTPClient ftp = new FTPClient();
//conectar al servidor and login
try
{
System.out.println( "Connecting" );
ftp.connect(server);
if(!ftp.login(username, password))
{
System.out.println( "Login failed" );
ftp.logout();
return;
}
int reply = ftp.getReplyCode();
System.out.println( "Connect returned: " + reply );
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.out.println( "Connection failed" );
return;
}
ftp.enterLocalPassiveMode();
FileInputStream in = new FileInputStream(local);
ftp.setFileType(ftp.BINARY_FILE_TYPE);
System.out.println( "Downloading File" );
boolean store = ftp.storeFile(remote,in);
in.close();
ftp.logout();
ftp.disconnect();
}
catch(Exception ex)
{
ex.printStackTrace();
}
 
Der Thread ist zwar aus der Steinzeit, aber weil ich gerade den FTP-Upload benötigt hab und auf diesen Thread gekommen bin, hier meine Lösungsvariante:

Der erste Parameter in storeFile ist der Name der Datei am Server, also muss hier auch etwas stehen.

Code:
FTPClient ftp = new FTPClient();
//conectar al servidor and login
try
{
    System.out.println( "Connecting" );
    ftp.connect(server);
    if(!ftp.login(username, password))
    {
        System.out.println( "Login failed" );
        ftp.logout();
        return;
    }
    int reply = ftp.getReplyCode();
    System.out.println( "Connect returned: " + reply );
    if (!FTPReply.isPositiveCompletion(reply)) {
        ftp.disconnect();
        System.out.println( "Connection failed" );
        return;
    }
    ftp.enterLocalPassiveMode(); 
    FileInputStream in = new FileInputStream(local);
    ftp.setFileType(ftp.BINARY_FILE_TYPE);
    System.out.println( "Uploading File" );
    boolean store = ftp.storeFile("test.txt",in);
    in.close();
    ftp.logout();
    ftp.disconnect();
}
catch(Exception ex)
{
    ex.printStackTrace();
}

greez
THEJS
 
So:
Code:
	FTPClient client = new FTPClient();
        FileInputStream fis = null;

        client.connect("bitchapp.cwsurf.de");
        client.login("usr_ftp_173803_0", "nhjkk3nhj");
        
        String filename = "daten.txt";
        fis = openFileInput(filename);
        client.storeFile(filename, fis);
        client.logout();
        fis.close();
Lädt er etwas hoch... die betonung liegt auf etwas^^
Der inhalt der TXT ist nämlich
Code:
0 1 0 0 1 0 1 1 1 1 0 1 0 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 1 0 1 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 ???

Also hat es definitiv etwas mit dem FileInputStream zu tun...
 
Aber vielleicht will mir (morgen früh) einer sagen, warum mein ProgressDialog:

ProgressDialog dialog = ProgressDialog.show(BitchAppActivity.this, "", "This could take a while...", true);
dialog.show();

Immer erst angezeigt wird, wenn es schon fast zu spät ist?
 
Zurück