2
votes

I have an FTP server on address ftp://192.168.1.14/ and port 21. I want to make a program in Python to connect to it and download it's files. It is my homework and I have to use TCP. My problem statement is

"You are required to implement a simple FTP operation using python-based TCP protocol. You will have to create an FTP server and client. Then you will have to create a TCP socket (SOC_SREAM) and establish connection between the server and the client module you created (programmed).Once the connection is established you are required to transfer a file (text file you store on server directory) to the client directory."

I was able to do it using ftplib but now I want to do it using simple socket tcp. What I have done so far is

import socket

s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)


s.bind(('ftp://192.168.1.14/', 21))
#also tried s.bind((socket.gethostname(), 21))

but I am receiving error which is

Traceback (most recent call last):
  File "server.py", line 34, in <module>
    s.bind(('ftp://192.168.1.14/', 21))
socket.gaierror: [Errno 11001] getaddrinfo failed

Hopefully you can help me. Thanks

EDIT:

when using s.bind((socket.gethostname(),21))

the error message is

Traceback (most recent call last):
  File "server.py", line 34, in <module>
    s.bind((socket.gethostname(), 21))
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
1
1. the address given must exist on your machine (it can matter if you develop on a system distinct from the target system). 2. The port must not be already in use, and must not be blocket by a firewall.Serge Ballesta

1 Answers

1
votes

I figured out the problem. Since I want to connect to the existing IP Adress, So the method for it is connect not bind. So correct code would be

import socket

s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)


s.connect((socket.gethostname(), 21))

print(s)