码迷,mamicode.com
首页 > 其他好文 > 详细

#FTP

时间:2017-08-10 23:52:47      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:分享   nec   style   self   inf   src   alt   init   active   

 

 

技术分享
 1 #FTP client
 2 
 3 import socket
 4 
 5 import os
 6 
 7 
 8 class FtpClient(object):
 9     def __init__(self):
10 
11         client = socket.socket()
12     def help(self):
13         msg = ‘‘‘
14             ls
15             pwd
16             cd ../..
17             get filename
18             put filename
19             ‘‘‘
20         print (‘‘)
21 
22     def connect(self,ip,port):
23 
24         clinet.connect((ip,port))
25         
26 
27     def interactive(self):
28 
29         #self.authenticate()
30         while True:
31             cmd =input(>>).strip()
32 
33             if len(cmd) == 0:continue
34 
35             cmd_str = cmd.split()[0]
36 
37             if hasattr(self,cmd_%s%cmd_str):
38                 func = getattr(self,cmd_%s%cmd_str)
39 
40                 func(cmd)
41             else:
42                 self.help()
43 
44     def cmd_put(self,*args):
45         cmd_split = arge[0].split()
46         if len(cmd_split) > 1 :
47             filename = cmd_split[1]
48             if os.path.isfile(filename):
49                 filesise = os.stat(filename).st_size
50                 
51                 #msg_str = ‘%s|%s‘ %(filename,filesize)
52                 msg_dic = {
53                     filename:filename,
54                     size:filesize
55                     overridden:True
56                            }
57 
58                 self.client.send(json.dumps(msg_dic).encode("utf-8"))
59                 #防止粘包,等服务器确认(标准请求码)
60                 server_response = self.client.recv(1024)
61                 f = open (filename,rb)
62                 for line inf:
63                     self.client.send(line)
64                 
65             else:
66                # print (filenmae,‘isnot exist‘)
67 
68                print (file upload success...)
69                f.close()
70 
71 
72     def
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95         
#FTP client

 

#FTP

标签:分享   nec   style   self   inf   src   alt   init   active   

原文地址:http://www.cnblogs.com/ujq3/p/7341830.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!