connecting ftp server using python
Asked Answered
W

3

7

I try to connect to an ftp server in my phone using python code and I get an error.

Code

import ftplib
server = ftplib.FTP()
server.connect('192.168.135.101', 5556)
server.login('svgn','123456')
print (server.dir())

Error

C:\Python27\python.exe C:/Users/alisivgin/PycharmProjects/untitled2/deneme2.py Traceback (most recent call last): File "C:/Users/alisivgin/PycharmProjects/untitled2/deneme2.py", line 3, in server.connect('192.168.135.101', 5556) File "C:\Python27\lib\ftplib.py", line 132, in connect self.sock = socket.create_connection((self.host, self.port), self.timeout) File "C:\Python27\lib\socket.py", line 571, in create_connection raise err socket.error: [Errno 10061] Hedef makine etkin olarak reddetti�inden ba�lant� kurulamad

Process finished with exit code 1

Thanks.

Ways answered 26/2, 2015 at 17:59 Comment(1)
Are you able to connect using any FTP client? Because the error indicates, the connection is not possible (the FTP server is not running?)Saville
C
11

Try below code, even i have faced same problems before.

import ftplib
server = ftplib.FTP()
server.connect('192.168.135.101', 5556)
server.login('svgn','123456')
# You don't have to print this, because this command itself prints dir contents 
server.dir()
Clippard answered 26/5, 2015 at 10:3 Comment(0)
O
7

You can also try below code

from ftplib import FTP


global ftp
ftp = FTP('192.168.135.101', user='svgn', passwd='123456')
print "connected to FTP"
Oodles answered 9/4, 2019 at 5:21 Comment(0)
U
0

It seems you don't have the connection towards the given IP (192.168.135.101) with port (5556) .Please try Telnet to the port

telnet 192.168.135.101 5556

from the command prompt(for windows users ) or from the Linux console .

If connectivity has some issue you can check with the network admin/your firewall rules to make the connection through.

If connectivity is fine then check FTP server is available in the remote server (192.168.135.101) in case of RHEL you can check

service vsftpd status

If it has FTP service(vsftpd (pid XXXX) is running response from the above command ) then check the FTP configuration .

Else (vsftpd: unrecognized service response from the above command) install the FTP server ) and try again for FTP. After all these troubleshooting, you should be able to access the remote server via FTP.

Unsavory answered 30/8, 2017 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.