0% found this document useful (0 votes)
4 views4 pages

TCP/IP File Transfer Client-Server Code

The document provides a Java program for a TCP/IP client-server file transfer application. The client prompts the user for a source file name and a destination path, then sends the file name to the server. If the file exists, the server sends its contents back to the client, which writes it to the specified destination path, completing the file transfer process.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

TCP/IP File Transfer Client-Server Code

The document provides a Java program for a TCP/IP client-server file transfer application. The client prompts the user for a source file name and a destination path, then sends the file name to the server. If the file exists, the server sends its contents back to the client, which writes it to the specified destination path, completing the file transfer process.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Using TCP/IP sockets, write a client ‒ server program to

make the client send the file name and to make the server
send back the contents of the requested file if present
import [Link].*;
import [Link].*;

public class ftpclient {


public static void main(String args[]) {
Socket s;
BufferedReader in, br;
PrintWriter pw;
String spath, dpath;
FileOutputStream fos;
int c;

try {
s = new Socket("localhost", 1111);
in = new BufferedReader(new InputStreamReader([Link]));
br = new BufferedReader(new InputStreamReader([Link]()));
pw = new PrintWriter([Link](), true);
[Link]("\nEnter source file to be copied:");
spath = [Link]();

[Link]("\nEnter destination path to transfer:");


dpath = [Link]();

fos = new FileOutputStream(dpath);


[Link](spath);

while ((c = [Link]()) != -1) {


[Link]((char) c);
[Link]();
}

[Link]("File Transfer Completed");


}
catch (Exception e) {
[Link](e);
}
}
}

You might also like