FTP and COMMANDS
File Transfer Protocol(FTP) is an application layer protocol that moves files
between local and remote file systems. It runs on the top of TCP, like HTTP.
To transfer a file, 2 TCP connections are used by FTP in parallel: control
connection and data connection.
What is control connection?
For sending control information like user identification, password, commands
to change the remote directory, commands to retrieve and store files, etc.,
FTP makes use of control connection. The control connection is initiated on
port number 21.
What is data connection?
For sending the actual file, FTP makes use of a data connection. A data
connection is initiated on port number 20.
FTP sends the control information out-of-band as it uses a separate control
connection. Some protocols send their request and response header lines
and the data in the same TCP connection. For this reason, they are said to
send their control information in-band. HTTP and SMTP are such examples.
FTP Session :
When an FTP session is started between a client and a server, the client
initiates a control TCP connection with the server-side. The client sends
control information over this. When the server receives this, it initiates a data
connection to the client-side. Only one file can be sent over one data
connection. But the control connection remains active throughout the user
session. As we know HTTP is stateless i.e. it does not have to keep track of
any user state. But FTP needs to maintain a state about its user throughout
the session.
Data Structures : FTP allows three types of data structures :
1. File Structure – In file-structure there is no internal structure and
the file is considered to be a continuous sequence of data bytes.
2. Record Structure – In record-structure the file is made up of
sequential records.
3. Page Structure – In page-structure the file is made up of
independent indexed pages.
FTP Commands – Some of the FTP commands are :
USER – This command sends the user identification to the server.
PASS – This command sends the user password to the server.
CWD – This command allows the user to work with a different directory or
dataset for file storage or retrieval without altering his login or accounting
information.
RMD – This command causes the directory specified in the path-name to be
removed as a directory.
MKD – This command causes the directory specified in the pathname to be
created as a directory.
PWD – This command causes the name of the current working directory to
be returned in the reply.
RETR – This command causes the remote host to initiate a data connection
and to send the requested file over the data connection.
STOR – This command causes to store of a file into the current directory of
the remote host.
LIST – Sends a request to display the list of all the files present in the
directory.
ABOR – This command tells the server to abort the previous FTP service
command and any associated transfer of data.
QUIT – This command terminates a USER and if file transfer is not in
progress, the server closes the control connection.
FTP Replies – Some of the FTP replies are :
200 Command okay.
530 Not logged in.
331 User name okay, need a password.
225 Data connection open; no transfer in progress.
221 Service closing control connection.
551 Requested action aborted: page type unknown.
502 Command not implemented.
503 Bad sequence of commands.
504 Command not implemented for that parameter.
• It is good for simple file transfers, such as during boot time.
• It uses UDP as transport layer protocols. Errors in the transmission
(lost packets, checksum errors) must be handled by the TFTP
server.
• It uses only one connection through well-known port 69.
• TFTP uses a simple lock-step protocol (each data packet needs to
be acknowledged). Thus the throughput is limited
Advantages of FTP(File Transfer Protocol):-
• speed is one of the advantages of FTP(File Transfer Protocol).
• File sharing also comes in the category of advantages of FTP in
this between two machines file can be shared on the network.
• Efficiency is more in FTP.
Disadvantages of FTP(File Transfer Protocol):-
• file size limit is the drawback of FTP only 2 GB size files can be
transferred.
• multiple receivers are not supported by the FTP.
• FTP does not encrypt the data this is one of the biggest drawbacks
of FTP.
Reliable and security: FTP is both secure and unsecured we use login IDs
and passwords making it secure but they can be attacked by hackers.
LAN WAN MAN
Differences between LAN, MAN, and WAN
Basis LAN MAN WAN
MAN stands for
LAN stands for local metropolitan area WAN stands for wide
Full-Form area network. network. area network.
Operates in small
areas such as the Operates in larger
Geographic same building or Operates in large areas such as country
Span campus. areas such as a city. or continent.
MAN’s ownership While WAN also might
LAN’s ownership is can be private or not be owned by one
Ownership private. public. organization.
While the
The transmission transmission speed Whereas the
Transmission speed of a LAN is of a MAN is transmission speed of a
Speed high. average. WAN is low.
Basis LAN MAN WAN
The propagation There is a moderate Whereas, there is a
Propagation delay is short in a propagation delay long propagation delay
delay LAN. in a MAN. in a WAN.
Whereas there is more
There is less While there is more congestion than MAN
Congestion congestion in LAN. congestion in MAN. in WAN.
While MAN’s design Whereas WAN’s design
LAN’s design and and maintenance and maintenance are
Design & maintenance are are difficult than also difficult than LAN
Maintenance easy. LAN. as well MAN.
Fault There is more fault While there is less In WAN, there is also
tolerance tolerance in LAN. fault tolerance. less fault tolerance.
DNS
An application layer protocol defines how the application processes running on
different systems, pass the messages to each other.
o DNS stands for Domain Name System.
o DNS is a directory service that provides a mapping between the name of a host on the
network and its numerical address.
o DNS is required for the functioning of the internet.
o Each node in a tree has a domain name, and a full domain name is a sequence of
symbols specified by dots.
o DNS is a service that translates the domain name into IP addresses. This allows the
users of networks to utilize user-friendly names when looking for other hosts instead
of remembering the IP addresses.
o For example, suppose the FTP site at EduSoft had an IP address of 132.147.165.50, most
people would reach this site by specifying ftp.EduSoft.com. Therefore, the domain
name is more reliable than IP address.
DNS is a TCP/IP protocol used on different platforms. The domain name space is
divided into three different sections: generic domains, country domains, and inverse
domain.
Generic Domains
o It defines the registered hosts according to their generic behavior.
o Each node in a tree defines the domain name, which is an index to the DNS database.
o It uses three-character labels, and these labels describe the organization type.
Label Description
aero Airlines and aerospace companies
biz Businesses or firms
com Commercial Organizations
coop Cooperative business Organizations
edu Educational institutions
gov Government institutions
info Information service providers
int International Organizations
mil Military groups
museum Museum & other nonprofit organizations
name Personal names
net Network Support centers
org Nonprofit Organizations
pro Professional individual Organizations
Country Domain
The format of country domain is same as a generic domain, but it uses two-character
country abbreviations (e.g., us for the United States) in place of three character
organizational abbreviations.
Inverse Domain
The inverse domain is used for mapping an address to a name. When the server has
received a request from the client, and the server contains the files of only authorized
clients. To determine whether the client is on the authorized list or not, it sends a query
to the DNS server and ask for mapping an address to the name.
39.9M
835
Exception Handling in Java - Javatpoint
Working of DNS
o DNS is a client/server network communication protocol. DNS clients send requests to
the. server while DNS servers send responses to the client.
o Client requests contain a name which is converted into an IP address known as a
forward DNS lookups while requests containing an IP address which is converted into
a name known as reverse DNS lookups.
o DNS implements a distributed database to store the name of all the hosts available on
the internet.
o If a client like a web browser sends a request containing a hostname, then a piece of
software such as DNS resolver sends a request to the DNS server to obtain the IP
address of a hostname. If DNS server does not contain the IP address associated with
a hostname, then it forwards the request to another DNS server. If IP address has
arrived at the resolver, which in turn completes the request over the internet protocol.
TCP
TCP stands for Transmission Control Protocol. It is a transport layer protocol that
facilitates the transmission of packets from source to destination. It is a connection-
oriented protocol that means it establishes the connection prior to the communication
that occurs between the computing devices in a network. This protocol is used with
an IP protocol, so together, they are referred to as a TCP/IP.
The main functionality of the TCP is to take the data from the application layer. Then
it divides the data into a several packets, provides numbering to these packets, and
finally transmits these packets to the destination. The TCP, on the other side, will
reassemble the packets and transmits them to the application layer. As we know that
TCP is a connection-oriented protocol, so the connection will remain established until
the communication is not completed between the sender and the receiver.
Features of TCP protocol
The following are the features of a TCP protocol:
o Transport Layer Protocol
TCP is a transport layer protocol as it is used in transmitting the data from the sender
to the receiver.
39.1M
876
Features of Java - Javatpoint
o Reliable
TCP is a reliable protocol as it follows the flow and error control mechanism. It also
supports the acknowledgment mechanism, which checks the state and sound arrival
of the data. In the acknowledgment mechanism, the receiver sends either positive or
negative acknowledgment to the sender so that the sender can get to know whether
the data packet has been received or needs to resend.
o Order of the data is maintained
This protocol ensures that the data reaches the intended receiver in the same order in
which it is sent. It orders and numbers each segment so that the TCP layer on the
destination side can reassemble them based on their ordering.
o Connection-oriented
It is a connection-oriented service that means the data exchange occurs only after the
connection establishment. When the data transfer is completed, then the connection
will get terminated.
o Full duplex
It is a full-duplex means that the data can transfer in both directions at the same time.
o Stream-oriented
TCP is a stream-oriented protocol as it allows the sender to send the data in the form
of a stream of bytes and also allows the receiver to accept the data in the form of a
stream of bytes. TCP creates an environment in which both the sender and receiver are
connected by an imaginary tube known as a virtual circuit. This virtual circuit carries
the stream of bytes across the internet.
Need of Transport Control Protocol
In the layered architecture of a network model, the whole task is divided into smaller
tasks. Each task is assigned to a particular layer that processes the task. In the TCP/IP
model, five layers are application layer, transport layer, network layer, data link layer,
and physical layer. The transport layer has a critical role in providing end-to-end
communication to the directly application processes. It creates 65,000 ports so that
the multiple applications can be accessed at the same time. It takes the data from the
upper layer, and it divides the data into smaller packets and then transmits them to
the network layer.
Working of TCP
In TCP, the connection is established by using three-way handshaking. The client sends
the segment with its sequence number. The server, in return, sends its segment with
its own sequence number as well as the acknowledgement sequence, which is one
more than the client sequence number. When the client receives the acknowledgment
of its segment, then it sends the acknowledgment to the server. In this way, the
connection is established between the client and the server.
Advantages of TCP
o It provides a connection-oriented reliable service, which means that it guarantees the
delivery of data packets. If the data packet is lost across the network, then the TCP will
resend the lost packets.
o It provides a flow control mechanism using a sliding window protocol.
o It provides error detection by using checksum and error control by using Go Back or
ARP protocol.
o It eliminates the congestion by using a network congestion avoidance algorithm that
includes various schemes such as additive increase/multiplicative decrease (AIMD),
slow start, and congestion window.
Disadvantage of TCP
It increases a large amount of overhead as each segment gets its own TCP header, so
fragmentation by the router increases the overhead.
TCP Header format
o Source port: It defines the port of the application, which is sending the data. So, this
field contains the source port address, which is 16 bits.
o Destination port: It defines the port of the application on the receiving side. So, this
field contains the destination port address, which is 16 bits.
o Sequence number: This field contains the sequence number of data bytes in a
particular session.
o Acknowledgment number: When the ACK flag is set, then this contains the next
sequence number of the data byte and works as an acknowledgment for the previous
data received. For example, if the receiver receives the segment number 'x', then it
responds 'x+1' as an acknowledgment number.
o HLEN: It specifies the length of the header indicated by the 4-byte words in the header.
The size of the header lies between 20 and 60 bytes. Therefore, the value of this field
would lie between 5 and 15.
o Reserved: It is a 4-bit field reserved for future use, and by default, all are set to zero.
o Flags
There are six control bits or flags:
1. URG: It represents an urgent pointer. If it is set, then the data is processed
urgently.
2. ACK: If the ACK is set to 0, then it means that the data packet does not contain
an acknowledgment.
3. PSH: If this field is set, then it requests the receiving device to push the data to
the receiving application without buffering it.
4. RST: If it is set, then it requests to restart a connection.
5. SYN: It is used to establish a connection between the hosts.
6. FIN: It is used to release a connection, and no further data exchange will
happen.
o Window size
It is a 16-bit field. It contains the size of data that the receiver can accept. This field is
used for the flow control between the sender and receiver and also determines the
amount of buffer allocated by the receiver for a segment. The value of this field is
determined by the receiver.
o Checksum
It is a 16-bit field. This field is optional in UDP, but in the case of TCP/IP, this field is
mandatory.
o Urgent pointer
It is a pointer that points to the urgent data byte if the URG flag is set to 1. It defines a
value that will be added to the sequence number to get the sequence number of the
last urgent byte.
o Options
It provides additional options. The optional field is represented in 32-bits. If this field
contains the data less than 32-bit, then padding is required to obtain the remaining
bits.
Congestion Control
o When large amount of data is fed to system which is not
capable of handling it, congestion occurs. TCP controls
congestion by means of Window mechanism. TCP sets a
window size telling the other end how much data segment to
send. TCP may use three algorithms for congestion control:
o · Additive increase, Multiplicative Decrease
o · Slow Start
o · Timeout React
Congestion policy in TCP –
1. Slow Start Phase: starts slowly increment is exponential to
threshold
2. Congestion Avoidance Phase: After reaching the threshold
increment is by 1
3. Congestion Detection Phase: Sender goes back to Slow start
phase or Congestion avoidance phase.
Slow Start Phase : exponential increment – In this phase after every RTT
the congestion window size increments exponentially.
Congestion Avoidance Phase : additive increment – This phase starts
after the threshold value also denoted as ssthresh. The size
of cwnd(congestion window) increases additive. After each RTT cwnd =
cwnd + 1.
3
Congestion Detection Phase : multiplicative decrement – If congestion
occurs, the congestion window size is decreased. The only way a sender can
guess that congestion has occurred is the need to retransmit a segment.
Retransmission is needed to recover a missing packet that is assumed to
have been dropped by a router due to congestion. Retransmission can occur
in one of two cases: when the RTO timer times out or when three duplicate
ACKs are received.
• Case 1 : Retransmission due to Timeout – In this case
congestion possibility is high.
(a) ssthresh is reduced to half of the current window size.
(b) set cwnd = 1
(c) start with slow start phase again.
• Case 2 : Retransmission due to 3 Acknowledgement
Duplicates – In this case congestion possibility is less.
(a) ssthresh value reduces to half of the current window size.
(b) set cwnd= ssthresh
(c) start with congestion avoidance phase
TCP AND HEADER FORMAT
Transmission Control Protocol TCP
Features
➢ TCP is reliable protocol. That is, the receiver always sends
either positive or negative acknowledgement about the data
packet to the sender, so that the sender always has bright
clue about whether the data packet is reached the destination
or it needs to resend it.
➢ TCP ensures that the data reaches intended destination in the
same order it was sent.
➢ TCP is connection oriented. TCP requires that connection
between two remote points be established before sending
actual data.
➢ TCP provides error-checking and recovery mechanism.
➢ TCP provides end-to-end communication.
➢ TCP provides flow control and quality of service.
➢ TCP operates in Client/Server point-to-point mode.
➢ TCP provides full duplex server, i.e. it can perform roles of
both receiver and sender.
Header
The length of TCP header is minimum 20 bytes and maximum
60 bytes.
▪ Source Port (16-bits): It identifies source port of the
application process on the sending device.
▪ Destination Port (16-bits): It identifies destination port of the
application process on the receiving device.
▪ Sequence Number (32-bits): Sequence number of data bytes
of a segment in a session.
▪ Acknowledgement Number (32-bits): When ACK flag is set,
this number contains the next sequence number of the data
byte expected and works as acknowledgement of the
previous data received.
▪ Data Offset (4-bits): This field implies both, the size of TCP
header (32-bit words) and the offset of data in current packet
in the whole TCP segment.
▪ Reserved (3-bits): Reserved for future use and all are set zero
by default.
▪ Flags (1-bit each):
o NS: Nonce Sum bit is used by Explicit Congestion
Notification signaling process.
o CWR: When a host receives packet with ECE bit set, it
sets Congestion Windows Reduced to acknowledge that
ECE received.
o ECE: It has two meanings:
✓ If SYN bit is clear to 0, then ECE means that the IP
packet has its CE (congestion experience) bit set.
✓ If SYN bit is set to 1, ECE means that the device is
ECT capable.
o URG: It indicates that Urgent Pointer field has significant
data and should be processed.
o ACK: It indicates that Acknowledgement field has
significance. If ACK is cleared to 0, it indicates that
packet does not contain any acknowledgement.
o PSH: When set, it is a request to the receiving station to
PUSH data as soon as it comes to the receiving
application without buffering it.
o RST: Reset flag has the following features:
✓ It is used to refuse an incoming connection.
✓ It is used to reject a segment.
✓ It is used to restart a connection.
o SYN: This flag is used to set up a connection between
hosts.
o FIN: This flag is used to release a connection and no
more data is exchanged thereafter. Because packets
with SYN and FIN flags have sequence numbers, they are
processed in correct order.
▪ Windows Size: This field is used for flow control between two
stations and indicates the amount of buffer (in bytes) the
receiver has allocated for a segment, i.e. how much data is the
receiver expecting.
▪ Checksum: This field contains the checksum of Header, Data,
and Pseudo Headers.
▪ Urgent Pointer: It points to the urgent data byte if URG flag is
set to 1.
▪ Options: It facilitates additional options which are not
covered by the regular header. Option field is always
described in 32-bit words. If this field contains data less than
32-bit, padding is used to cover the remaining bits to reach
32-bit boundary.