How to transfer file from server to client

I am making a server printer where all the system can take print out from the Printer installed on the server
i am not able to send file from the client to the Server. I am Attaching the code Please Help me it is my college project.
Server.java*
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;
import java.io.File;
class Server
     static final int PORT     = 26548; //Server Listening port
     static String path;
     public static void main(String args[])
          System.out.println("Starting Server");
          receive();
     public static void receive()
          while ( true )
               try
                    //Create a socket
                    ServerSocket srvr = new ServerSocket(PORT);
                    Socket skt = srvr.accept();
                    String clientname= skt.getInetAddress().getHostAddress();
                    int clientport=skt.getPort();
                    long time = System.currentTimeMillis();
                    path= "C:\\Ankit Gupta\\Programs\\"+clientname+"\\"+time+" test.pdf";
                    System.out.println("File Recieved from : "+clientname+" : "+clientport);
                    //HttpServletRequest req;
                    //String remoteHost = req.getRemoteHost();
                    //String adr = getRemoteUser();
                    FileOutputStream fos = new FileOutputStream(path);
                    BufferedOutputStream out = new BufferedOutputStream(fos);
                    BufferedInputStream in = new BufferedInputStream( skt.getInputStream() );
                    //Read, and write the file to the socket
                    int i;
                    System.out.println("Receiving data...");
                    while ((i = in.read()) != -1)
                         out.write(i);
                    out.flush();
                    in.close();
                    out.close();
                    skt.close();
                    srvr.close();
                    System.out.println("Transfer complete.");
                    printfile();
               catch(Exception e)
                    System.out.print("Error! It didn't work! " + e + "\n");
               try
                    Thread.sleep(1000);
               catch (InterruptedException ie)
                    System.err.println("Interrupted");
          } //end infinite while loop
     public static void printfile()
          delete();
     public static void delete()
          try
               Thread.sleep(5000);
          catch (InterruptedException ie)
               System.err.println("Interrupted");
          System.out.println("Deleting file");
          File f = new File(path);
     // Make sure the file or directory exists and isn't write protected
          if (!f.exists())
               throw new IllegalArgumentException("Delete: no such file or directory: " + path);
     if (!f.canWrite())
               throw new IllegalArgumentException("Delete: write protected: "+ path);
          // If it is a directory, make sure it is empty
     if (f.isDirectory())
               String[] files = f.list();
               if (files.length > 0)
               throw new IllegalArgumentException("Delete: directory not empty: " + path);
     // Attempt to delete it
          boolean success = f.delete();
          if (!success)
               throw new IllegalArgumentException("Delete: deletion failed");
Client.java_
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class Client extends JFrame {
static final int PORT = 26548; //Server Listening Port
static File file;
static final String HOST = "10.35.9.152";//Server Address     
JTextField m_fileNameTF = new JTextField(25);
JFileChooser m_fileChooser = new JFileChooser();
Client() {
m_fileNameTF.setEditable(false);
     JButton openButton = new JButton("Open");
     openButton.addActionListener(new OpenAction());
     JPanel content = new JPanel();
     content.setLayout(new FlowLayout());
     content.add(openButton);
content.add(m_fileNameTF);
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setContentPane(content);
     this.setSize(400,200);
class OpenAction implements ActionListener {
     public void actionPerformed(ActionEvent ae) {
          int retval = m_fileChooser.showOpenDialog(Client.this);
          if (retval == JFileChooser.APPROVE_OPTION) {
               file = m_fileChooser.getSelectedFile();
          m_fileNameTF.setText(file.getAbsolutePath());
               send(file.getAbsolutePath());
public static void main(String[] args) {
     JFrame window = new Client();
     window.setVisible(true);
     public static boolean send( String filename )
     try
          System.out.println("Connecting to Server");
          Socket skt = new Socket(HOST, PORT);
          //Create a file input stream and a buffered input stream.
          FileInputStream fis = new FileInputStream(filename);
          BufferedInputStream in = new BufferedInputStream(fis);
          BufferedOutputStream out = new BufferedOutputStream( skt.getOutputStream() );
          //Read, and write the file to the socket
          int i;
          System.out.println("Connected to Server");
          System.out.println("Sending data...\n");
          while ((i = in.read()) != -1)
               out.write(i);
               //System.out.println(i);
          System.out.println("Transfer complete.");
          //Close the socket and the file
          out.flush();
          out.close();
          in.close();
          skt.close();
          return true;
     catch( Exception e )
               send(file.getAbsolutePath());
          return false;
}

I am making a server printer where all the system can take print out from the Printer installed on the server
i am not able to send file from the client to the Server. I am Attaching the code Please Help me it is my college project.
Server.java*
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;
import java.io.File;
class Server
     static final int PORT      = 26548; //Server Listening port
     static String path;
     public static void main(String args[])
          System.out.println("Starting Server");
          receive();
     public static void receive()
          while ( true )
               try
                    //Create a socket
                    ServerSocket srvr = new ServerSocket(PORT);
                    Socket skt = srvr.accept();
                    String clientname= skt.getInetAddress().getHostAddress();
                    int clientport=skt.getPort();
                    long time = System.currentTimeMillis();
                    path= "C:\\Ankit Gupta\\Programs\\"+clientname+"\\"+time+" test.pdf";
                    System.out.println("File Recieved from : "+clientname+" : "+clientport);
                    //HttpServletRequest req;
                    //String remoteHost = req.getRemoteHost();
                    //String adr = getRemoteUser();
                    FileOutputStream fos = new FileOutputStream(path);
                    BufferedOutputStream out = new BufferedOutputStream(fos);
                    BufferedInputStream in = new BufferedInputStream( skt.getInputStream() );
                    //Read, and write the file to the socket
                    int i;
                    System.out.println("Receiving data...");
                    while ((i = in.read()) != -1)
                         out.write(i);
                    out.flush();
                    in.close();
                    out.close();
                    skt.close();
                    srvr.close();
                    System.out.println("Transfer complete.");
                    printfile();
               catch(Exception e)
                    System.out.print("Error! It didn't work! " + e + "\n");
               try
                    Thread.sleep(1000);
               catch (InterruptedException ie)
                    System.err.println("Interrupted");
          } //end infinite while loop
     public static void printfile()
          delete();
     public static void delete()
          try
               Thread.sleep(5000);
          catch (InterruptedException ie)
               System.err.println("Interrupted");
          System.out.println("Deleting file");
          File f = new File(path);
         // Make sure the file or directory exists and isn't write protected
          if (!f.exists())
               throw new IllegalArgumentException("Delete: no such file or directory: " + path);
         if (!f.canWrite())
               throw new IllegalArgumentException("Delete: write protected: "+ path);
          // If it is a directory, make sure it is empty
         if (f.isDirectory())
               String[] files = f.list();
               if (files.length > 0)
               throw new IllegalArgumentException("Delete: directory not empty: " + path);
         // Attempt to delete it
          boolean success = f.delete();
          if (!success)
               throw new IllegalArgumentException("Delete: deletion failed");
Client.java_
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class Client extends JFrame {
static final int PORT = 26548; //Server Listening Port
static File file;
static final String HOST = "10.35.9.152";//Server Address     
JTextField   m_fileNameTF  = new JTextField(25);
JFileChooser m_fileChooser = new JFileChooser();
Client() {
   m_fileNameTF.setEditable(false);
     JButton openButton = new JButton("Open");
     openButton.addActionListener(new OpenAction());
     JPanel content = new JPanel();
     content.setLayout(new FlowLayout());
     content.add(openButton);
  content.add(m_fileNameTF);
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setContentPane(content);
     this.setSize(400,200);
class OpenAction implements ActionListener {
     public void actionPerformed(ActionEvent ae) {
          int retval = m_fileChooser.showOpenDialog(Client.this);
          if (retval == JFileChooser.APPROVE_OPTION) {
               file = m_fileChooser.getSelectedFile();
             m_fileNameTF.setText(file.getAbsolutePath());
               send(file.getAbsolutePath());
public static void main(String[] args) {
     JFrame window = new Client();
     window.setVisible(true);
     public static boolean send( String filename )
     try
          System.out.println("Connecting to Server");
          Socket skt = new Socket(HOST, PORT);
          //Create a file input stream and a buffered input stream.
          FileInputStream fis = new FileInputStream(filename);
          BufferedInputStream in = new BufferedInputStream(fis);
          BufferedOutputStream out = new BufferedOutputStream( skt.getOutputStream() );
          //Read, and write the file to the socket
          int i;
          System.out.println("Connected to Server");
          System.out.println("Sending data...\n");
          while ((i = in.read()) != -1)
               out.write(i);
               //System.out.println(i);
          System.out.println("Transfer complete.");
          //Close the socket and the file
          out.flush();
          out.close();
          in.close();
          skt.close();
          return true;
     catch( Exception e )
               send(file.getAbsolutePath());
          return false;
}

Similar Messages

  • How to transfer file from server to client pc with out client unknown

    Hi,
    Fill some form ,then submit, that time generate one xml file put in server,then the same file transfer to client machine fixed path(c:/download/) with out any pop up message..
    Pls help ..
    pls give some code idea
    Thanks in Advance
    karthik

    Thanks
    Vendor application only call the URL with parameter
    to get the File in secured manner. OK.
    the Vendor
    application may be in java or not..NET ?
    so in that case
    also do.so what ? is your problem solved or not ?
    you may need to make webservices.

  • How to download file from server to client's local ??

    How to download a file from the server to the client's local machine in a particular folder without users intervention ie. 'Save As" prompt of the browser should be avoided and if the client clicks on "Download" button, the file should get automaticaly downloaded to say, "c:/reports/' on his/her local machine. This is for Java based web appliaction.

    http://jguru.com/faq/view.jsp?EID=10646

  • How to save file from server to client machine

    Hi,
    By using POI library i'm writing values to the existing excel sheet which is available in server. After i written values to the excel, i want to save the same file to the client machine.
    How to achieve this.
    I googled about this, but still i didn't get any clear idea.
    Thanks in advance,
    SAN

    Sameera,
    No, i can't understand what is the meaning of the following code:
    public void doDownload(FacesContext facesContext, OutputStream outputStream) {
    // write the neccessary code to get the download data from the Model
    String data = getDownloadData();
    // save to the output stream
    try {
    OutputStreamWriter writer = new OutputStreamWriter(outputStream,"UTF-8");
    writer.write(data);
    writer.close();
    outputStream.close();
    } catch (IOException e) {
    // handle I/O exceptions
    can you please explain this code little more.
    Edited by: san-717 on Feb 29, 2012 2:30 PM

  • How can i transfer more than one file from server to client

    Hi,
    our requirement is transfer more than one files from server to client using the
    webutil_file_transfer.as_to_client_with_progress.One file transfer is already working in our system.If anybody know the solution please inform
    regards
    mat

    just an idea ...
    for this purpose let us put aside security concerns and other potential problems....
    -- Get the content of a server directory with Filter and create zip file
    1) create a class that implements java.io.FilenameFilter ...
    2) define accept() method ...
    3) call File.list() with the filter as a parameter. The returned array of strings will have all the names that passed through the accept() filter
    4) use java.util.Zip to create ZIP file on the server side
    -- I think it is better to create this functionality as a separate Java class, put it in required folder and after it
    -- use Forms->Program->"Import Java class" to create pl/sql wrappers, than to create wrappers for all classes and code in pl/sql
    5) use webutil to transfer file on the client
    6) use Java on client side to unzip transferred file
    if you think this is not too complicated, you should try ...
    Regards,
    Vladimir

  • How to transfer file from application server to presentation server in background?

    Hi Experts,
    How to transfer file from application server to presentation server in background?
    Thanks in advance
    Namita

    Thanks Raman and Challa,
    We want to move file from application server to Shared folder, not on local machine. We checked FM which you guys have provided but those are not able to read file from application server.
    We need this program to run in background so that we can use this in daily process chain.
    Appreciate your inputs on this.
    Thanks,
    Namita

  • Move files from server to client

    I have create txt file in server directory using UTL_FILE package,
    and I put in the directory in server.
    Server platform is linux. and client platform in Windows.
    What I want to ask is there any possibilities to copy that file from server to client using pl/sql ? could all of you "The Gurus" give me a script example ?
    Thanks a lot.
    regards,
    indra

    > What I want to ask is there any possibilities to copy that file from server
    to client using pl/sql
    No. Not really.
    Think about it.. the file is on the server. PL/SQL code executes inside the Oracle server session that is servicing the client.
    Just how is PL/SQL (on the server) suppose to reach out and push that file to a client's file system and directory?
    PL/SQL cannot do this. You need something on the client that will accept the file. You need something in-between the client and PL/SQL that will handle the transfer of the file. This something can be ftp, scp, tftp, NetBIOS etc.
    Anyway you look at this, it does not make sense. You are turning the server into the client that needs to push the file. You are turning the client into a server that needs to accept the file.
    Why? This is contrary to the basic client-server RDBMS architecture. You are adding more complexities and more moving parts to the architecture by forcing a swap of client and server roles. The are now a far greater likelihood of errors and bugs and failures.
    It does not make sense to do it this way.
    What is the business requirement you are trying to satisfy? Instead of us trying to help you to hack a flawed solution, let us rather assist you in determining the correct and proper solution.

  • How to transfer file from ipod touch to i tunes. i have files in my ipod , ut itunes is  new so its telling if u sync the ipod all the files will be replaced but no files in the itunes.. so kindly help me how to transfer the files  from i pod to itunesb

    how to transfer file from ipod touch to i tunes. i have files in my ipod , ut itunes is  new so its telling if u sync the ipod all the files will be replaced but no files in the itunes.. so kindly help me how to transfer the files  from i pod to itunes......

    Some of the information below has subsequently appeared in a document by turingtest2: Recovering your iTunes library from your iPod or iOS device - https://discussions.apple.com/docs/DOC-3991
    Your i-device was not designed for unique storage of your media. It is not a backup device and media transfer was designed for you maintaining a master copy of your media on a computer which is itself properly backed up against loss. Syncing is one way, computer to device, updating the device content to the content on the computer, not updating or restoring content on a computer. The exception is iTunes Store purchased content.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer - http://support.apple.com/kb/HT1848 - only media purchased from iTunes Store
    For transferring other items from an i-device to a computer you will have to use third party commercial software. Examples (check the web for others; this is not an exhaustive listing, nor do I have any idea if they are any good):
    - Senuti - http://www.fadingred.com/senuti/
    - Phoneview - http://www.ecamm.com/mac/phoneview/
    - MusicRescue - http://www.kennettnet.co.uk/products/musicrescue/
    - Sharepod (free) - http://download.cnet.com/SharePod/3000-2141_4-10794489.html?tag=mncol;2 - Windows
    - Snowfox/iMedia - http://www.mac-videoconverter.com/imedia-transfer-mac.html - Mac & PC
    - iexplorer (free) - http://www.macroplant.com/iexplorer/ - Mac&PC
    - Yamipod (free) - http://www.yamipod.com/main/modules/downloads/ - PC, Linux, Mac [Still updated for use on newer devices? No edits to site since 2010.]
    - 2010 Post by Zevoneer: iPod media recovery options - https://discussions.apple.com/message/11624224 - this is an older post and many of the links are also for old posts, so bear this in mind when reading them.
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive - https://discussions.apple.com/docs/DOC-3141 - dates from 2008 and some outdated information now.
    Copying Content from your iPod to your Computer - The Definitive Guide - http://www.ilounge.com/index.php/articles/comments/copying-music-from-ipod-to-co mputer/ - Information about use in disk mode pertains only to older model iPods.
    Get Your Music Off of Your iPod - http://howto.wired.com/wiki/Get_Your_Music_Off_of_Your_iPod - I am not sure but this may only work with some models and not newer Touch, iPhone, or iPad.
    Additional information here https://discussions.apple.com/message/18324797

  • How to get file from server while click on link

    Hi,
    i created on link and i gave one server path to select file from server but while clickinng on link it no displaying any thing.
    following is the Destination url that i gave for the item.
    /u08/app/appvis/xxex/inst/xxex_apps/xxrbe/logs/appl/conc/log/
    please tell me how to get file from server while click on link.

    Ok I got your requirement now.
    If you are getting file names from view attribute then you should not be adding destination URI property for the link.
    Instead you can use OADataBoundValueViewObject API.
    Try below code in your controller processRequest method:
    I am assuming that you are using classic table.
    Also in below example it considers OAMessageStyleText and you can replace it with link item if you want.
    OATableBean tableBean =
    (OATableBean)webBean.findChildRecursive("<table item id>");
    OAMessageStyledTextBean m= (OAMessageStyledTextBean)tableBean.findChildRecursive("<message styled text in table item id>");
    OADataBoundValueViewObject tip1 = new OADataBoundValueViewObject(m, "/u08/app/appvis/xxex/inst/xxex_apps/xxrbe/logs/appl/conc/log/"+"<vo attr name which stores file name for each row>");
    m.setAttributeValue(oracle.cabo.ui.UIConstants.DESTINATION_ATTR, tip1);
    Regards,
    Sandeep M.

  • How to transfer files from an iMac to a PC?

    I copied files (.pdf, .doc) from my iMac to a memory stick for a colleague in a charity. He has a PC and can't open them. The folder in the memory stick shows the file extension as .fpbf  Please advise on how to transfer files from an iMac to a PC.

    Format the memory stick as "fat" then copy the files to it.

  • How to transfer files from Pc to mobiles?

    HI,
    How to transfer files from Pc to mobiles?
    what are the Methods to do transferring files.
    Sri

    hi
    tell me which type of files u want to transfer
    are they text files or j2me software
    clear it
    R

  • How to transfer files from iBook to reader?

    How to transfer files from iBook to reader

    The first step is to export the PDF from iBooks to your computer (this cannot be one on your iPad or iPhone). Connect your iPad or iPhone to your syncing computer. Open iTunes. Select your device (how to do this depends on which version of iTunes you are running). Click on the Books tab at the top. In the current version of iTunes 11, I had to choose to view by PDFs. Then I could drag a PDF from the iTunes window to my Desktop.
    Then follow the instructions in this document to import the PDF(s) into Adobe Reader:
    http://forums.adobe.com/docs/DOC-2532
    Not so easy, I'm afraid. Easier if you just keep copies of your PDFs on your computer.

  • How to transfer files from MacBook Pro pages app to iPad mini pages app?

    How to transfer files from MacBook Pro pages app to iPad mini pages app?

    The above assumes you are running current software.
    Mac - OX X 10.9.2, Pages 5.1.
    iPad - iOS 7.0.6, Pages 2.1.

  • How to transfer files from 1 ipad to another

    how to transfer files from 1 ipad to another

    Depends what you are trying to transfer.
    Are you just trying to add content such as apps, music and photos?
    Or are these files that were created by such apps as pages and numbers?
    You can download content that was purchased in the itunes or app store by signing into same account.
    You can dowload any documents saved to icloud by signing into the same account.
    You can create a backup of the first ipad and restore the second from that backup.
    You can import or sync the content from the first ipad into itunes and then manually sync to the second.
    But this all depends on what you are actually trying to do.
    http://www.apple.com/support/ipad/syncing/

  • How to transfer files from mac to ipad without using itunes

    how to transfer files from mac to ipad without using itunes ???
    as i want to use my ipad for official use as well...please suggest..

    well to be 100% technical, no you didn't but that aside, it good to know there are ways for people to transfer music into the default apps without iTunes, if they have a need.
    I tend to use 3rd party apps for documents, like your mentioned iExplorer etc, which are handy.
    I see from a search the two "apps" you mentioned are not iOS apps, which I had assumed, SyncPod and FreeSync are apps for your computer, that would explain their access to the default Music/Video apps.
    I had wondered how Apple had allowed iOS apps in the store that could get around the sandboxing in iOS of apps.
    Message was edited by: CGW3

Maybe you are looking for

  • Displaying the list of numbers in the box on the screen

    Hi folks, This is what i am looking to achieve, I have an agency number (regulierer -field from jhaga) table Each agency has several advertisers listed to it, in the same table separate field inserent contains the advertiser numbers when I type in th

  • How to change the name of your iphone

    when you use the iphone for a hotspot, how do you change that name when it shows up it in the list to choose? thanks

  • Output message from XI Validations aganist Schma?

    Hi,    My scenario is such that whenever a message is outputted by XI it must be validated aganist the schema.I am using XSL mapping in interface mapping. By default the output message is not validating aganist the output schema. As per the suggestio

  • Ken Burns and portrait pictures

    I'm doing my first slideshow. iPhoto 5.0.4 and 23" screen. Full screen is all right, for landscape pictures, that is (even when they are cropped). By default, portraits are scaled as to "fill the height", that means big black columns at left & right.

  • IDOC inbound .

    Hi Gurus , i am working on IDOC Inbound process , actually it has to update picking net weight and total weight , in am using stadard message type 'SHPCON' , internally this uses the function module 'WS_DELIVERY_UPDATE_2' , but after IDOC has been po