×

Discussion Board

Results 1 to 10 of 10

Thread: FTP2ME

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    FTP2ME

    I wish to send a file from one server to my phone. For this, I use the function call
    Code:
    public void retr(java.io.OutputStream outputStream,
                     java.lang.String filename)
    Here's what the technical documentation said about it :

    public void retr(java.io.OutputStream outputStream,
    java.lang.String filename)
    throws java.io.IOException,
    FtpProtocolException

    Retrieve This command causes the server-DTP to transfer a copy of the file, specified in the pathname, to the server- or user-DTP at the other end of the data connection. The status and contents of the file at the server site shall be unaffected.

    Throws:
    java.io.IOException
    FtpProtocolException
    My problem is that the program stops at this function (retr).

    Here is my program :

    Code:
     try {
                ftpcon = new Ftp2Me(host, port, user, pass);
                String cheminftp = ftpcon.pwd() ; // to know the working directory of my server
    
               
                String url = "file:///Mes images/ftppp2.txt" ; // ftppp2 it's the path of the file I want to create
    
                OutputStream os = Connector.openOutputStream(url) ;
                StreamConnection sc = null ;
                sc =        (StreamConnection) Connector.open(url) ;
                os = sc.openOutputStream() ;
                DataOutputStream dos = new DataOutputStream(os) ;
    
                ftpcon.retr(dos,cheminftp+"/text.txt") ; //I think the problem is here with 'dos'
       
                } catch (IOException ex) {
                    ex.printStackTrace();
               } catch (FtpProtocolException ex) {
                    ex.printStackTrace();
               }
    Do I use correctely the function "OutputStream" and "StreamConnection" ?

    Thank you in advance.

    Borhane. (French Student).

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: FTP2ME

    I wish to send a file from one server to my phone
    Please explain what are you trying to --> Send a file from your PC to your mobile phone ?
    or From Phone to PC ?

    You want to do it over internet ? using GSM network - GPRS data transfer?
    Thanks,
    Ekta

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    Re: FTP2ME

    I traying to send a file (.txt) from my SERVER to my mobile phone - with FTP (using a package called FTP2ME)

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: FTP2ME

    here is a small correction in your code:

    Code:
    try {
                ftpcon = new Ftp2Me(host, port, user, pass);
                String cheminftp = ftpcon.pwd() ; // to know the working directory of my server
    
               
                String url = "file:///Mes images/ftppp2.txt" ; // ftppp2 it's the path of the file I want to create
    
                OutputStream os = null; //Connector.openOutputStream(url) ;
                StreamConnection sc = null ;
                sc =        (StreamConnection) Connector.open(url) ; // this line is trying to open connection to filesystem - no use here
                os = sc.openOutputStream() ; // Optput Stream should be opened on ftpcon
                DataOutputStream dos = new DataOutputStream(os) ;
    
                ftpcon.retr(dos,cheminftp+"/text.txt") ; //I think the problem is here with 'dos'
       
                } catch (IOException ex) {
                    ex.printStackTrace();
               } catch (FtpProtocolException ex) {
                    ex.printStackTrace();
               }
    Check the documentation of FTP2ME.... your code is doing something else...
    Thanks,
    Ekta

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    Re: FTP2ME

    No its not working. but I think the problem comes from here :
    OutputStream os = Connector.openOutputStream(url) ;
    StreamConnection sc = null ;
    sc = (StreamConnection) Connector.open(url) ;
    os = sc.openOutputStream() ;
    DataOutputStream dos = new DataOutputStream(os) ;
    Here is the link to see the documentation package FTP2ME : http://www.koders.com/java/fid9FDA18...spx?s=226#L145

  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: FTP2ME

    FTP2me is project is to create a J2ME (CLDC 1.0, MIDP 2.0) compatible ftp client library. The main component of the library is a class named Ftp2Me. It implements all of the ftp commands described in RFC959.

    The purpose is to connect to a FTP server and download a file from the server to the client (mobile).
    You can program it like this:
    Code:
    try {
                ftpcon = new Ftp2Me(host, port, user, pass);
                String cheminftp = ftpcon.pwd() ; // to know the working directory of my server
             
                String url = "file:///Mes images/ftppp2.txt" ; // ftppp2 it's the path of the file I want to create on the mobile phone using JSR 75 FCA API
    
                FileConnection fconn = (FileConnection)Connector.open(url);
                if (!fconn.exists()) fconn.create();  // create the file if it doesn't exist
                OutputStream os = fconn.openOutputStream() ;
    
                ftpcon.retr(os,cheminftp+"/text.txt") ; // It needs OS only not DOS
       
    // The above line retr, fetchs the text.txt file from server and writes it to OutputStream i.e. on the file system
    
               fconn.close();
    
                } catch (Exception e) {
                    ex.printStackTrace();
               } catch (FtpProtocolException ex) {
                    ex.printStackTrace();
               }
    Try this code, it will work if you have the permissions to write to the target folder on the device and if your text.txt exist on the FTP server.

    I could write this code after reading the implementation of retr method of FTP2ME
    Code:
    public void retr(OutputStream outputStream, String filename) throws IOException, FtpProtocolException {
            PasvInfo pi = pasv();
    
            sendLine("RETR " + filename);
    
            SocketConnection dataInput = (SocketConnection) Connector.open("socket://"+pi.ip+":"+pi.port);
            
            expectResponse(150);
    
            InputStream in = dataInput.openInputStream();
    
            byte[] buffer = new byte[128];
            int bytesRead = 0;
            while ((bytesRead = in.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            in.close();
            outputStream.close();
            dataInput.close();
    
            expectResponse(226);
        }
    Thanks,
    Ekta

  7. #7
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    Re: FTP2ME

    It's almost good : except that the file created is empty !

  8. #8
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    Re: FTP2ME

    I added these lines : (but its not working)
    ... ...
    path = System.getProperty(photos);
    String url = path + "ftppp2.txt";
    ftpcon.cwd("/ppmob") ;
    ... ...
    ftpcon.type('A') ; //Select the type ASCII

  9. #9
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: FTP2ME

    If you are using FTP2ME library, use its source code in your project and try to print (SOP) the data read in retr() method before its written to the filesystem outputstream - see if you get the data.

    We need to identify if the issue is on the FTP server side or the client side Filesystem.
    Thanks,
    Ekta

  10. #10
    Registered User
    Join Date
    Jun 2010
    Posts
    6

    Re: FTP2ME

    thank you for your advice.
    After hours of searching I found nothing.
    I think the problem comes from the phone and not the server.

    I wonder how can we know the path to any directory on the phone ? Without using :
    String path = System.getProperty (fileconn.dir.photos);
    Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×