使用python连接ftp服务器

Ali*_*gın 5 ftp ftplib python-2.7

我尝试使用 python 代码连接到手机中的 ftp 服务器,但出现错误。

代码

import ftplib
server = ftplib.FTP()
server.connect('192.168.135.101', 5556)
server.login('svgn','123456')
print (server.dir())
Run Code Online (Sandbox Code Playgroud)

错误

C:\Python27\python.exe C:/Users/alisivgin/PycharmProjects/untitled2/deneme2.py Traceback(最近一次调用):文件“C:/Users/alisivgin/PycharmProjects/untitled2/deneme2.py”,第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? 库鲁拉马德

进程以退出代码 1 结束

谢谢。

小智 8

试试下面的代码,即使我以前也遇到过同样的问题。

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()
Run Code Online (Sandbox Code Playgroud)


Par*_*ain 7

您也可以尝试下面的代码

from ftplib import FTP


global ftp
ftp = FTP('192.168.135.101', user='svgn', passwd='123456')
print "connected to FTP"
Run Code Online (Sandbox Code Playgroud)