FTP客户端: 这块应该是在数据库里面存储:用户名,密码 这里测试就暂时用一个字典: jesn@jesn-virtual-machine:~$ cat socket_Client.py import socket, time HOST = 'localhost' PORT = 9999 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) dirc = {'jesn':110, 'mary':120} def check_user(): while 1: user = raw_input('please enter your user').strip() if user in dirc.keys(): count = 0 while 1: if count <3: passwd = int(raw_input('please enter your passwd').strip()) if passwd == dirc[user]: print 'welcome in my ftp!' break else: print 'error passwd!!! please enter again!' count = count +1 continue else: print 'username not in the list!!!' continue break check_user() while 1: Input = raw_input('Please input the command :').strip() if len(Input) == 0: continue s.sendall(Input) user_input = Input.split() if user_input[0] == 'get': with open(user_input[1],'wr') as f: f.write(s.recv(1024)) print 'getting ...' if s.recv(1024) == 'ftpisdown':continue if not s.recv(1024):break if user_input[0] == 'set': with open(user_input[1],'rb') as f: y = f.read() s.sendall(y) print 'senting...' if s.recv(1024) == 'receiveDown':continue if not s.recv(1024):break data = s.recv(8192) time.sleep(2) #print 'Received', repr(data) print data s.close() jesn@jesn-virtual-machine:~$ FTP 服务器端: jesn@jesn-virtual-machine:~/ftp$ cat ../thread_socket_server.py import SocketServer,commands,time class MyTCPHandler(SocketServer.BaseRequestHandler): def handle(self): while 1: self.data = self.request.recv(1024).strip() print "{} wrote:".format(self.client_address[0]) if not self.data: print "client %s is dead!"%self.client_address[0] break user_input = self.data.split() print user_input[0] if user_input[0] == 'get': with open(user_input[1],'rb') as f: y = f.read() self.request.sendall(y) time.sleep(2) self.request.sendall('ftpisdown') continue if user_input[0] == 'set': with open(user_input[1],'wb') as f: y = self.request.recv(1024) f.write(y) print 'writeing...' self.request.sendall('receiveDown') continue comman_statu,comman_test = commands.getstatusoutput(self.data) if len(comman_test) != 0: self.request.sendall(comman_test) print comman_test else: self.request.sendall('Done') if __name__ == "__main__": HOST, PORT = "localhost",9999 server = SocketServer.ThreadingTCPServer((HOST,PORT), MyTCPHandler) server.serve_forever() jesn@jesn-virtual-machine:~/ftp$
socket实现FTP
原创文章标签 socket Python 文章分类 Python 后端开发
上一篇:Python中set集合的整理
下一篇:lamp 一键脚本
-
linux之socket编程
linux之socket编程
数据 端口号 IP -
socket实现简单的FTP
socketserver、struct模块练习,简易的FTP
网络 项目演示 客户端 服务端 数据 -
python网络编程socket模块实现ftp上传下载
python使用socket, struct实现ftp上传下载功能
socket python 网络编程 -
Socket、TCP/IP、HTTP、FTP及网络编程
1 这些都是什么既然是网络传输,涉及几个系统之间的交互,那么首先要考虑的是如何准确的定位到网络上的一台或几台主机,另定Interne
Socket TCPIP HTTP FTP 网络编程 -
FTP实验
实验一实验要求:  
配置 FTP -
编程实现基于tcp的socket编程
server端:public class Server { public static void main(Stri
socket java 客户端 服务器 输入流 -
【Socket编程二】利用Socket实现聊天通信的编程实例
利用Socket实现聊天通信的编程实例在上文中,介绍了Socket相关的内容以及Soc
java socket 通信 聊天 客户端