Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connecting ftp server using python

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.

like image 421
Ali Şıvgın Avatar asked Feb 26 '15 17:02

Ali Şıvgın


People also ask

How do I connect to an FTP server?

You need to open your Internet browser and start typing the FTP Server's Hostname (or IP Address) and the FTP port number (in case the FTP Server is utilizing a separate port than the actual default port "21" for the FTP connections) in the address box and press Enter.

What does Ftplib do Python?

Python has a module called ftplib that allows the transfer of files through the FTP protocol. The ftplib module allows us to implement the client side of the FTP protocol, and it allows users to connect to servers in order to send and receive files.


2 Answers

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()
like image 146
Jambu Avatar answered Sep 24 '22 00:09

Jambu


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"
like image 38
Paras jain Avatar answered Sep 25 '22 00:09

Paras jain