public class FileTransferClient
extends java.lang.Object
FileTransferClient is used for transferring a particular file to the server.| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
clientId
Identifier of the client.
|
private java.net.InetAddress |
ip
IP address of the server.
|
private static org.apache.log4j.Logger |
log
Used to log different events.
|
private java.net.Socket |
mySocket
Socket on the server used for file transfer.
|
private int |
port
TCP port on the server on which the file transmission occurs.
|
| Constructor and Description |
|---|
FileTransferClient(java.lang.String ip,
int port,
java.lang.String clientId)
Constructs the object.
|
| Modifier and Type | Method and Description |
|---|---|
private boolean |
requestTransferPermission()
Requests from the server permissions to transfer the file.
|
private void |
transferFile(java.io.File myFile)
Transfers the file to the server.
|
boolean |
uploadFile(java.io.File myFile)
Uploads file
myFile to the server. |
private static org.apache.log4j.Logger log
private java.net.Socket mySocket
private java.net.InetAddress ip
private int port
private java.lang.String clientId
public FileTransferClient(java.lang.String ip,
int port,
java.lang.String clientId)
throws java.io.IOException
ip - IP address of the serverport - TCP port on the server on which the file transmission occursclientId - identifier of the clientjava.io.IOException - if the IP address is invalidpublic boolean uploadFile(java.io.File myFile)
throws java.io.FileNotFoundException
myFile to the server.
File can be transferred by transferFile only if permissions are granted by requestTransferPermissionmyFile - file to be uploadedtrue if the upload succeeded, false otherwisejava.io.FileNotFoundException - if the file to be transferred does not existprivate boolean requestTransferPermission()
throws java.io.IOException
true if the permission to transfer the file was granted, false otherwisejava.io.IOException - if communication error between the client and the server occursprivate void transferFile(java.io.File myFile)
throws java.io.FileNotFoundException,
java.io.IOException
myFile - file to be transferredjava.io.FileNotFoundException - if the file to be transferred does not existjava.io.IOException - if communication error between the client and the server occurs