Trasnfer File from Client to server

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;
}Edited by: Ankit__Gupta on Jul 24, 2009 1:59 AM

the network is working perfectly fineThe network is timing out your connect attempts so there is something wrong somewhere.
catch will give the error msg or the entire try block. but will it give for the exact line?Suppose you try it yourself and find out?
by the way i m catching the exception i m just not printing it.Yes I am aware of that, thanks, I can read, and that's exactly what I commented on, and by the way Java forces you to catch the exception, so there's no virtue in that. On the contrary. Catchingand ignoring the exception is why its taken five days to debug this simple problem. Never do that.

Similar Messages

  • Transfer file from client to server using http

    HI friends,
    I want to transfer files from client to server...I tried that with the help of socket and rmi..........
    But Http is only the best mechanism for my application..........
    Without using servlets, how to transfer files with the help of http.....
    Any help would be appreciated.......

    Google is your friend, and appearently www.jguru.com also:
    http://www.jguru.com/faq/view.jsp?EID=160

  • Urgent - Upload a file from Client to Server.

    Need to load a file from the client machine to the Server running 9iAS Rel. 1 on a HP Unix Machine.
    We are using Forms 6i. We have looked into the File Upload Utility demo code provided with Forms 6i - but have been unsuccessful in reusing it. PLS HELP

    Duplicate post.
    Upload a file from client to server by forms in E-Bussiness Suite R12
    Re: Upload a file from client to server by forms in E-Bussiness Suite R12.

  • How to upload file from client to server in servlets.

    actually in my application i have to upload file from client m/c to server.
    it is not possible through file i/p stream as fileStreams does not work on network. Please mail me if you have any solution to this.
    Thank's in advance............

    Haii roshan
    Pls go through this thread..
    http://forum.java.sun.com/thread.jspa?forumID=45&threadID=616589
    regards
    Shanu

  • Unload file from client to server in APEX

    Hi All!
    I have a file on a client computer.
    I have my APEX application.
    Do you know how to unload file from client computer to server in my APEX application ?
    Best regards,
    Roman

    See if these links help:
    http://download-east.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/up_dn_files.htm#CJAHDJDA
    http://concept2completion.net/c2/wwv_flow_file_mgr.get_file?p_security_group_id=727128741744148&p_fname=fileDownload.pdf
    Doug

  • How to upload file from client to server in jsp

    hello , In my application i have a requirement to upload picture and from it save to picture one with origional size and another with 100 * 100 size

    Hi,
    Give destination path is server address. for that u use
    application.getRealPath("/");
    It will return the server path.
    -regards
    Anna

  • How to upload file from client to server

    Can someone please help.
    User needs to browse file on his desktop and upload file using browse button. This file should then be uploaded to the server. I am using javascript in the front end and servlet in the back.
    Any help will be highly appreciated.
    Thanks,
    Indrasish

    Jakarta Commons FileUpload is the standard way of doing the file uploading these days. You can find source, binaries and documentation at the Jakarta Site http://jakarta.apache.org/ . The Commons has a number of subprojects, so start with the Commons libraries, then find FileUpload.
    Brian

  • How to deploy Forms, Reports and Menu from Client to Server machine

    Dear Experts,
    I have one requirement to deploy the Forms, Reports and Menu from client machine to server machine.
    Deployment involves the following steps :
    1. Firstly we have to search the selected file in a folder where the .fmx is present ( in Server machine) and take the back up of the the existing file in the server (Source and destination paths will be available).
         Ex. If the existing FMB name is TEST.fmx then the backup file should be TEST_sysdate.fmx.
    2. Secondly we have to transfer the file from the client folder (or from another folder of the same server) to the server folder where the back up exists.
    Please help me to search/rename/copy/replace the _.fmx/.rdf/.rep/.mmx_ files from client to server.
    We are using
    9i Database.
    10g Forms and reports.
    SQL Developer tool.
    OS is Windows (Client and Server).
    Help me out to attach a file of front end screen which we are planning to develop. It will give a clear picture on this requirement.
    Thanks :)
    Edited by: 941175 on Jun 17, 2012 9:09 AM
    Edited by: 941175 on Jun 17, 2012 9:12 AM
    Edited by: 941175 on Jun 17, 2012 9:14 AM

    941175
    Welcome to the forum. Please take a while to go through the FAQ to be found to the top right of the page.
    Your issue is more to do with batch files rather than Forms. The only relation with Forms, as I see it, is that you will be using HOST/CLIENT_HOST to start a batch file with the file name to be deployed as a parameter passed to it.
    You need to rewrite either a CMD batch file or a Powershell script to achieve what have set out to do.
    For CMD batch files look up http://www.robvanderwoude.com/battech.php , or any of the other excellent resources available on the internet.
    Regards,

  • Copy file from client machine to unix db server

    Dear all,
    I have oracle form 10g, and data base server using 10 r 2,
    I have an oracle for to browse client XML file and return the name of the file including the path to TEXT item what I want to do after that is to copy the seelcted file from the client to DB server (hint this server over Unix operating system)
    I tried
    V_Cpy_Result := Webutil_File.Copy_File ('C:\File_Name.Xml', '/u01/oradata/odsuat/ssr_xml_dir/Outbound/File_Name.Xml');
    but this does't work, please provide me with the way or the command that I can copy the selected file from client to Unix DB server...

    Hello,
    If you want to transfer files between client machine and A.S. or database machine, use the Webutil file_transfer package's functions.
    Francois

  • Copy file from client PC to server in a web deployed application

    I have developed one application using Oracle forms 6i, which is deployed on the web server.
    I run this application from a client PC in Internet Explorer using internet.
    I want to copy one file from the client PC to the web server.
    I have done following things
    - Created a shared folder on the server and given full rights to every one on this folder
    - I use 'net use' command in my program to connect to this shared folder
    - I use copy command to copy file from local client pc to server. This copy command I am executing using host command of my programming (PL/SQL: eg. host('copy abc.txt \\server\share\') )
    But this does not work.
    When I do the same thing in command window, it works.
    (ie. Start-Run cmd to open command window and then type the above copy command)
    Can you please tell me, how to copy a file from client PC to the sever in Web deployed application?
    Thanks

    I downloaded D2KWUtil from the link suggested by you. It has very nice example demo form. But the documentation provided says following
    Using D2KWUTIL in Web Deployed Applications
    The use of this library is not supported with Web deployed applications.
    In a web deployment scenario not all functions within D2KWUTIL will work. Any function that interacts with the User Interface (such as those in the WIN_API_DIALOG package) will fail.
    Any interaction with the O/S by other functions will all be executed on the NT server and will act within, or return information pertinant to, the environment on that machine. For instance GET_COMPUTER_NAME will return the Server’s name, not the name of the computer that the Client browser is running on. Likewise COPY_FILE will copy files in the Forms Server not on the Client.
    Functions such as those in WIN_API_BITOP will continue to work without change.
    so this will not work in web deployed application.
    Any other suggestion?
    Thanks

  • To upload a file from client machine to server machine

    Hi everybody!
    Could anyone plz help me. I am struck in a problem
    I want to transfer a file from client's machine to server but I am not able to upload
    It is tranferring the file only to the local machine
    I am using orielley package It is transferring files only to my local machine but not to the server .Can anyone correct it. It's very urgent
    how to write the relative path for server
    I am using this path and it is not uploading
    MultipartRequest multi = new MultipartRequest(request, "../<administrator>:<dev2daask>@dev2:C:/123data/", 5 * 1024 * 1024);
    Here is my code:
    <%@ page import="java.util.*" %>
    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="com.oreilly.servlet.MultipartRequest"%>
    <%
    try {
    // Blindly take it on faith this is a multipart/form-data request
    // Construct a MultipartRequest to help read the information.
    // Pass in the request, a directory to saves files to, and the
    // maximum POST size we should attempt to handle.
    // Here we (rudely) write to the server root and impose 5 Meg limit.
    MultipartRequest multi = new MultipartRequest(request, "../<administrator>:<dev2daask>@dev2:C:/123data/", 5 * 1024 * 1024);
    out.println("<HTML>");
    out.println("<HEAD><TITLE>UploadTest</TITLE></HEAD>");
    out.println("<BODY>");
    out.println("<H1>UploadTest</H1>");
    // Print the parameters we received
    out.println("<H3>Params:</H3>");
    out.println("<PRE>");
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
    String name = (String)params.nextElement();
    String value = multi.getParameter(name);
    out.println(name + " = " + value);
    out.println("</PRE>");
    // Show which files we received
    out.println("<H3>Files:</H3>");
    out.println("<PRE>");
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
    String name = (String)files.nextElement();
    String filename = multi.getFilesystemName(name);
    String type = multi.getContentType(name);
    File f = multi.getFile(name);
    out.println("name: " + name);
    out.println("filename: " + filename);
    out.println("type: " + type);
    if (f != null) {
    out.println("length: " + f.length());
    out.println();
    out.println("</PRE>");
    catch (Exception e) {
    out.println("<PRE>");
    out.println("</PRE>");
    out.println("</BODY></HTML>");
    %>

    you have not understood my point
    how does this code will run on servlet when I want to upload a file from client's
    machine to server machine
    what I am doing is I am giving an option to the user that he/she can browse the file and then select any file and finally it's action is post in the jsp form for which I have sent the code
    All the computers are connected in LAN
    So how to upload a file from client's machine to server's machine
    Plz give me a solution

  • JSP to Upload file from client machine to Web Server!

    Hi,
    I want to upload a file from client machine to web server in order to send it as email attachment, How can I do it? After uploading the file the class should give me the path where the file is stored on the web server and the file name in return!
    I know the HTML <file> field but dont know how to copy it on web server, HTML Part will be:
    <FORM ENCTYPE="multipart/form-data"
    method="POST" action="My.jsp">
    <INPUT TYPE="file" NAME="mptest">
    <INPUT TYPE="submit" VALUE="upload">
    </FORM>
    Please help!
    Thanks,
    - Rahul

    You can use cos.jar provided by O'Reilly from http://www.servlets.com/cos/. Take a look at com.oreilly.servlet.multipart.* classes.
    Package is provided with source, classes, documentation and, of course, ready-to-use jar file.
    It is really usefull and - ready!

  • How to upload file from client machine to  database in server machine?

    I am developing a web application. this application is suppose to take file from client machine and store that to database in the server side.
    My jsp form is of multi part type. but I am confused about what to write in servlet.
    Can any one help me ?
    Edited by: chinmaya_mishra on Feb 16, 2009 2:55 AM
    Edited by: chinmaya_mishra on Feb 16, 2009 2:58 AM

    http://www.google.com/search?q=jdbc+blob
    Blob processing varies between databases; see also examples for whatever database you are using, e.g.
    http://www.google.com/search?q=jdbc+blob+oracle
    If you are storing text data instead of binary data, replace "blob" by "clob" in the searches.

  • How to Serialize a file path from client to server?

    I am using serializing concepts in java. I am stuck, that how can i send only file path from client to server?

    Um, ill take a wild guess and say that youre trying to
    access a file on another computer using that path?
    That wont work.
    What could the other computer possible do
    with that path unless both computers are networked to a
    common drive, or if they are networked to each other in a way
    where the root in the file path would point to the same place
    on either computer?

  • How to delete file from client machine

    Hi all,
    we are using the DataBase: oracle:10g,
    and forms/reports 10g(developer suite 10g-10.1.2.2).
    can anybody help me how to delete the file from client machine in specified location using webutil or any
    (i tried with webutil_host & client_host but it is working for application server only)
    thank you.

    hi
    check this not tested.
    PROCEDURE OPEN_FILE (V_ID_DOC IN VARCHAR2)
    IS
    -- Open a stored document --
    LC$Cmd Varchar2(1280) ;
    LC$Nom Varchar2(1000) ;
    LC$Fic Varchar2(1280);
    LC$Path Varchar2(1280);
    LC$Sep Varchar2(1) ;
    LN$But Pls_Integer ;
    LB$Ok Boolean ;
    -- Current Process ID --
    ret WEBUTIL_HOST.PROCESS_ID ;
    V_FICHERO VARCHAR2(500);
    COMILLA VARCHAR2(4) := '''';
    BOTON NUMBER;
    MODO VARCHAR2(50);
    URL VARCHAR2(500);
    Begin
    V_FICHERO := V_ID_DOC;
    LC$Sep := '\';--WEBUTIL_FILE.Get_File_Separator ; -- 10g
    LC$Nom := V_FICHERO;--Substr( V_FICHERO, instr( V_FICHERO, LC$Sep, -1 ) + 1, 100 ) ;
    --LC$Path := CLIENT_WIN_API_ENVIRONMENT.Get_Temp_Directory ;
    LC$Path := 'C:';
    LC$Fic := LC$Path || LC$Sep || LC$Nom ;
    If Not webutil_file_transfer.DB_To_Client
    LC$Fic,
    'TABLE_NAME',
    'ITEM_NAME',
    'WHERE'
    ) Then
    Raise Form_trigger_Failure ;
    End if ;
    LC$Cmd := 'cmd /c start "" /MAX /WAIT "' || LC$Fic || '"' ;
    Ret := WEBUTIL_HOST.blocking( LC$Cmd ) ;
    LN$But := WEBUTIL_HOST.Get_return_Code( Ret ) ;
    If LN$But 0 Then
    Set_Alert_Property( 'ALER_STOP_1', TITLE, 'Host() command' ) ;
    Set_Alert_Property( 'ALER_STOP_1', ALERT_MESSAGE_TEXT, 'Host() command error : ' || To_Char( LN$But ) ) ;
    LN$But := Show_Alert( 'ALER_STOP_1' ) ;
    LB$Ok := WEBUTIL_FILE.DELETE_FILE( LC$Fic ) ;
    Raise Form_Trigger_Failure ;
    End if ;
    If Not webutil_file_transfer.Client_To_DB
    LC$Fic,
    'TABLE_NAME',
    'ITEM_NAME',
    'WHERE'
    ) Then
    NULL;
    Else
    Commit ;
    End if ;
    LB$Ok := WEBUTIL_FILE.DELETE_FILE( LC$Fic ) ;
    Exception
    When Form_Trigger_Failure Then
    Raise ;
    End ;sarah

Maybe you are looking for

  • How to secure information completed on a fill in form?

    How do I secure or lock the information I've entered onto an acrobat fill in form so I can send the form to others and the info can't be changed?

  • How to define the application parameter 'sap.xss.BaseConfigurationID'

    Hello All, I am developing a webdynpro ESS custom self service application. I have completed the development of the DC. But at the end when I am creating the application for the DC, I am not able to figure it out how to define the application paramet

  • HT204266 I deleted safari browser from my iPad 2, need to download again?

    I deleted safari browser from my iPad 2, need to download again?

  • Printing a pages document

    Hey, I really don't know if this is a problem with Pages or actually with my HP printer, but for some reason I can not get the entire document to print. I have a two fold insert that I made up using Pages, it looks great on the computer, and it even

  • Phishing attempt?

    I just got an email from "Katie Salomon"... How the heck am I receiving spam from my own email address? It was an ad trying to link me to the Facebook page of luxuryitalianrealty.com.  I didnt click the link, but I'm quite concerned that someone has