Click to See Complete Forum and Search --> : Tranfer file from local machine to a Server


Neeraj
September 25th, 1999, 11:44 AM
With the attached code I m able to send a file on a particular server but not with the contects, it is coping empty file

javacode
// Program to implement a simple socket client
import java.net.*;
import java.io.*;
public class Client3
{
public static void main(String []args) throws IOException
{
Socket clientSocket;
// to write to the socket
PrintStream out = null;
// to read from the socket
BufferedReader in = null;
try
{
clientSocket = new Socket("000.00.000.000",21);
out = new PrintStream(clientSocket.getOutputStream());
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
// System.err.println("Unidentified hostname");
}
catch(UnknownHostException e)
{
System.err.println("Unidentified hostname");
System.exit(1);
}
catch(IOException e)
{
System.err.println("Couldn't get I/O");
System.exit(1);
}

// read from the socket
String login = in.readLine();
System.out.println(login);

// accepting User
// writing to Socket
out.println("USER manifest");

// reading from the socket and display
String user = in.readLine();
System.out.println(user);

// accepting password
// writing to Socket
out.println("PASS cm_manifest");

// reading from socket and display
String pass = in.readLine();
System.out.println(pass);

// port information for data connection
// writting to socket
out.println("PORT 000,00,000,000,0,21");

// to read from the socket and display
String port = in.readLine();
System.out.println(port);

// transfering file from current directory to server
// writting to socket
out.println("STOR test.java");

// to read from the socket and display
String trans = in.readLine();
System.out.println(trans);

out.close();
in.close();
}
}
/javacode

poochi
September 25th, 1999, 02:39 PM
Are u really transfering the file ? I could able to see the following lines only..


// transfering file from current directory to server
// writting to socket
out.println("STOR test.java");




It seems you are sending a string not the file ( I could not able to understand what that
STOR for ).

Open that file in your client side , read each and every line and send it to the server.



RandomAccessFile rFile = new RandomAccessFile( "d:\somefile.txt" );
String strLine = null;
while( ( strLine = rFile.readLine()) != null ){
out.println( strLine );
}