File upload mit ftp

Status
Nicht offen für weitere Antworten.
J

Java2k5

Gast
Hi @all,

ich habe folgende Problemstellung:

ich hab aus einer lokalen Datenbank eine XML File exportiert.
Diese XML File will ich nun per Internet Verbindung (wenn möglich ftp) auf einen anderen Server hochladen und in die xindice xml-database (http://xml.apache.org/xindice) schreiben.

Habt ihr da eine Idee wie ich das am besten anstellen kann?
Wie lade ich eine File (XML Datei) auf einen anderen Server?


Grüße Java2k5
 
J

Java2k5

Gast
Im Moment bin ich so weit aber ich bekomm immernoch eine Exception als Ausgabe:


java.net.UnknownHostException: ftp://servernname
!!!Die angegebenen Serverdaten sind ungültig
java.lang.NullPointerException
!!!Fehler beim schließen der Verbindung!!!

Kann des ein, das meine firewall einfach den ftp port blockt und ich deshalb nicht raus komme?



mein code looks like that:
(Servername, Username und Passwort abgeändert)


Code:
import ftp.*;
import java.io.*;
import java.net.*;

/************************************************************************************
 * This is an FTP program and an example of using FtpBean.
 * 
 * Program Description:
 * It connects to a ftp server.
 * Go to a directory.
 * Then list its content with help of the FtpListResult class.
 * Finally, it gets a binary file. 
 * In the downloading progress, it tells how many bytes are being downloaded.
 *
 * Note that this class implements the FtpObserver interface, which
 * make this class have the ability to monitor the downloading or 
 * uploading progress.
 * If you don't need to monitor it, then you don't need to implement this interface.
 ***********************************************************************************/



class FtpProg implements FtpObserver
{

	//Variablen Deklaration
    FtpBean ftp;
    long num_of_bytes = 0;




// Main
    public static void main(String[] args) throws Exception
    { 
       System.out.println("********************************************************************************");
       System.out.println("FTP Programm Version 1.0 beta");
       System.out.println();       
       System.out.println("********************************************************************************");
       System.out.println();
       System.out.println();
       System.out.println();
                             
     FtpProg myFtpProg = new FtpProg();      
     myFtpProg.connect();
     //ftp.listDirectory();
     //ftp.getFile();
     myFtpProg.close();
     	 	   
       System.out.println(); 	   
       System.out.println();	 	       
       System.out.println();	 	                   
       System.out.println();
       System.out.println("********************************************************************************");
       System.out.println("Programm Ende");
       System.out.println();      
       System.out.println("********************************************************************************");
        
        
        
    }//public static void main(String[] args)





    public FtpProg()
    {
        // Create a new FtpBean object.
        ftp = new FtpBean();
    }//public ftp()



    // Connect to a ftp server.
    public void connect()
    {
        try
        {
            ftp.ftpConnect("ftp://servername", "username", "passwort");
        }        
        catch(Exception e)
        {
            System.out.println(e);                    
       	try
    	{
     	 	PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out, "Cp850"));
     	 	out.println("!!!Die angegebenen Serverdaten sind ungültig!!!");
     	 	out.flush();
    	}
    	catch (UnsupportedEncodingException d)
    	{
      	System.err.println(d);
      	}      
      }        
   }//public void connect()
           
           

    // Close connection
    public void close()
    {
        try
        {
          	ftp.close();
        } 	catch(Exception e)
      		{
            System.out.println(e);                        
        try
    	{
     	 	PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out, "Cp850"));
     	 	out.println("!!!Fehler beim schließen der Verbindung!!!");
     	 	out.flush();
    	}
    	catch (UnsupportedEncodingException d)
    	{
      	System.err.println(d);
      	}      
     		}
    }//public void close()



    // Go to directory pub and list its content.
    public void listDirectory()
    {
        FtpListResult ftplrs = null;

        try
        {
            // Go to directory 'pub/redhat/redhat-6.2/i386/RedHat/RPMS'.
            ftp.setDirectory("pub/redhat/redhat-6.2/i386/RedHat/RPMS");
            // Get its directory content.
            ftplrs = ftp.getDirectoryContent();
        } catch(Exception e)
        {
            System.out.println(e);
        }

        // Print out the type and file name of each row.
        while(ftplrs.next())
        {
            int type = ftplrs.getType();
            if(type == FtpListResult.DIRECTORY)
                System.out.print("DIR\t");
            else if(type == FtpListResult.FILE)
                System.out.print("FILE\t");
            else if(type == FtpListResult.LINK)
                System.out.print("LINK\t");
            else if(type == FtpListResult.OTHERS)
                System.out.print("OTHER\t");
            System.out.println(ftplrs.getName());
        }
    }//public void listDirectory()



    // Get the file.
    public void getFile()
    {
        try
        {
            // Get the binary file 'export.xml' and save it to
            // the name 'local_file_name' in the hard disk.
            // Passing this class which implements the FtpObserver interface to 
            // monitor this downloading progress. Every time new bytes are read,
            // the byteRead(int) method of this class is invoked by the bean.
            ftp.getBinaryFile("export.xml", "local_file_name", this);
        } catch(Exception e)
        {
            System.out.println(e);
        }
    }//public void getFile()
    
    
    

    // Implemented for FtpObserver interface.
    // To monitor download progress.
    public void byteRead(int bytes)
    {
        num_of_bytes += bytes;
        System.out.println(num_of_bytes + " of bytes read already.");
    }

    // Needed to implements by FtpObserver interface.
    public void byteWrite(int bytes)
    {
    }
            
    
}//class ftp implements FtpObserver
 
J

Java2k5

Gast
ZUR INFO

Die methoden
//ftp.listDirectory();
//ftp.getFile();
sind auskommentiert, da sie noch von einem anderen prog stammen, mitdem ich verschiedene rpm packete von einem linux server abholte.
 

Bleiglanz

Gesperrter Benutzer
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
D CSV File Upload Netzwerkprogrammierung 5
M HTTP File Upload mit Prozessbar Funktioniert nicht. Netzwerkprogrammierung 8
5 File Upload/ ClassNotFoundException Netzwerkprogrammierung 9
R HTTP HttpURLConnection Large File Upload Netzwerkprogrammierung 1
E upload progress bei einem http file post Netzwerkprogrammierung 5
L file upload / download über http Netzwerkprogrammierung 5
D Socket Gute Idee?: File als byte[] per ObjectIOStream übertragen Netzwerkprogrammierung 3
S Webserver für Jar File Netzwerkprogrammierung 4
H Applet soll XML-File auf Server speichern Netzwerkprogrammierung 6
R Apache HttpClient File Download? Netzwerkprogrammierung 3
0 Apache Commons File Object bekommen Netzwerkprogrammierung 4
D Server Client Verbindung - Unexpected End of File - Invalid HTTP Response Netzwerkprogrammierung 4
S RSS-Feed aus ini File Netzwerkprogrammierung 4
Z File über Socket lesen Netzwerkprogrammierung 3
N Socket File über Socket vom Server an Client versenden Netzwerkprogrammierung 15
F Protokoll file:/// Netzwerkprogrammierung 2
B JNLP File -> Web Application Netzwerkprogrammierung 10
DStrohma RMI Security Manager & Policy-File Netzwerkprogrammierung 8
DeviAn Über ein Linux Server ein Windows Server nach einer File fragen Netzwerkprogrammierung 6
P java file.exists() zuzerstörbar Netzwerkprogrammierung 7
E java.net.SocketException: Unexpected end of file from server Netzwerkprogrammierung 2
G SMB-File ausführen Netzwerkprogrammierung 15
J Problem beim Senden von File Netzwerkprogrammierung 4
J Mit der File Api Dateien von anderen Rechnern lesen ? Netzwerkprogrammierung 3
I unc pfad für die klasse file? Netzwerkprogrammierung 4
V file transfer problem Netzwerkprogrammierung 2
P File von http-Server kopieren Netzwerkprogrammierung 5
N File Transfer Netzwerkprogrammierung 5
D wie kann ich rmic ein .jar file übergeben? Netzwerkprogrammierung 3
R File chooser übers Netzwerk Netzwerkprogrammierung 3
G file download über https mit p12 Zertifikat Netzwerkprogrammierung 4
D Performance Problem beim File senden, empfangen Netzwerkprogrammierung 4
T file auf einen server laden Netzwerkprogrammierung 4
J FTP Upload über Proxy funktioniert nicht Netzwerkprogrammierung 1
P nanoHttp upload.html page lädt nicht Netzwerkprogrammierung 4
B FTPS Upload Netzwerkprogrammierung 3
M Google Image Upload Netzwerkprogrammierung 12
M Apache Solr doc & pdf Upload Netzwerkprogrammierung 8
C apache commons net ftp bei upload unvollständig Netzwerkprogrammierung 3
C HTTP Mediawiki Upload Netzwerkprogrammierung 9
D FTP Pfadangabe für ftp-upload funktioniert nicht Netzwerkprogrammierung 5
1 Upload problem! org.apache.commons.net.ftp Netzwerkprogrammierung 3
E Applet zum Datei-Upload Netzwerkprogrammierung 3
P Bilder: FTP-Upload funktioniert nicht richtig Netzwerkprogrammierung 2
W HTTP-Upload Netzwerkprogrammierung 2
K Datei-Upload per FTP Netzwerkprogrammierung 2
E Upload großer Dateien? Netzwerkprogrammierung 5
eskimo328 progress bar mit upload speed Netzwerkprogrammierung 19
J Java Programm für Upload von Dateien per HTTP Netzwerkprogrammierung 7

Ähnliche Java Themen

Neue Themen


Oben