Results 1 to 8 of 8
  1. #1
    michal.g is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Lightbulb Client-Server folder synch (FTP)

    Hello everyone!

    I'm creating ftp program which server will send not existing files on client to him.
    There is method responsible for creating connection and sending list of files on client written by me.

    Java Code:
    [JAVA]//client method
    public void enableClient() throws IOException, ClassNotFoundException {
            System.out.print("Rozpoczęto działanie klienta");
            strIP = jtfIP.getText();
            intPort = Integer.parseInt(jtfNrPortu.getText());
            clientPath= "C:/serweris/";
            sck = new Socket(strIP, intPort);
            bufferedInput = new BufferedInputStream(sck.getInputStream());
            listFilesForServer = new PrintWriter(sck.getOutputStream(), true);
    ////////////////////        
            System.out.print("Connection with : " + "\n" + sck.getInetAddress().toString());
            System.out.print("Synch...");
    ///////////////////      
            String text;
            listFilesForServer.append("Files in client folder:");
            File f = new File(clientPath);
            File[] tabClientFiles= f.listFiles();
            for (int j = 0; j < tabClientFiles.length; j++) {
                if (tabClientFiles[j].isFile()) {
                    text = tabClientFiles[j].getName();
                     listFilesForServer.println("\n" + text);
                }
            }
    
            listFilesForServer.flush();   
        }[/JAVA]


    Any ideas?
    Last edited by michal.g; 02-08-2014 at 07:34 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Client-Server folder synch (FTP)

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    What is the problem you are having?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    michal.g is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Client-Server folder synch (FTP)

    I have no idea how to get synchronization between 2 folders on client and on server (server is only file sender).

    Java Code:
    /server method
    public void launchServer() throws IOException, ClassNotFoundException {
            System.out.print("Server is working");
            try {
                srwrSck = new ServerSocket(Integer.parseInt(jtfNrPortu.getText()));
                srwrSck.setReuseAddress(true);
                sck = srwrSck.accept();
                input = new BufferedReader(new InputStreamReader(sck.getInputStream()));
                output = new BufferedOutputStream(sck.getOutputStream());
               // PrintWriter outToClient = new PrintWriter(sck.getOutputStream());
                oos =new ObjectOutputStream(sck.getOutputStream());
            } catch (IOException e) {
                 System.out.print("Nie można połączyć!");
            }
      
             serverPath= "C:/serwer/";
             System.out.print("Connected with : " + "\n" + sck.getInetAddress().toString());
             System.out.print("Synch...");
    
            String list;
            System.out.print("List of server files:");
            File serverDir= new File(serverPath);
            serverFilesTable = serverDir.listFiles();
            for (int j = 0; j < serverFilesTable .length; j++) {
                if (serverFilesTable [j].isFile()) {
                    list = serverFilesTable [j].getName();
                    System.out.print(list);
                }
            }       
    
        }
    Last edited by michal.g; 02-08-2014 at 07:56 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Client-Server folder synch (FTP)

    Can you make some simple example of what you are trying to do?
    Make lists of the contents of the folders on the server and on the client and describe what would need to be done to get synchronization.

    For example:
    Server:
    --folder1
    ---fileA
    --folder2
    ---fileX

    Client:
    --folder1
    ---fileA
    --folder2
    ---fileY
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    michal.g is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Client-Server folder synch (FTP)

    But how can I get list of files on client for example and send to server?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Client-Server folder synch (FTP)

    The File class has methods for getting a list of files. Create Strings from that list and send them to the server.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    michal.g is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Client-Server folder synch (FTP)

    Maybe I will try sth more simple- there is possibility to check files on the sever by client?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Client-Server folder synch (FTP)

    to check files on the sever by client?
    The client could send a request to the server for a list of the files it has.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 06-03-2012, 10:48 AM
  2. Replies: 1
    Last Post: 06-03-2012, 04:07 AM
  3. Replies: 2
    Last Post: 09-24-2010, 12:31 PM
  4. Replies: 1
    Last Post: 10-05-2008, 04:12 PM
  5. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 10:18 AM

Tags for this Thread

Posting Permissions

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