from ctypes import *
          import os
          import sys
          import ftplib

          class KANFtp:
          ??? ftp = ftplib.FTP()
          ??? bIsDir = False
          ??? path = ""
          ??? def __init__(self, host):
          ??????? self.ftp.connect( host )
          ???????????
          ??? def Login(self, user, passwd ):
          ??????? self.ftp.login( user, passwd )
          ??????? print self.ftp.welcome
          ??? def DownLoadFile( self, LocalFile, RemoteFile ):
          ??????? file_handler = open( LocalFile, 'wb' )
          ??????? self.ftp.retrbinary( "RETR %s" %( RemoteFile ), file_handler.write )
          ??????? file_handler.close()
          ??????? return True
          ???
          ??? def UpLoadFile( self, LocalFile, RemoteFile ):
          ??????? if os.path.isfile( LocalFile ) == False:
          ??????????? return False
          ??????? file_handler = open( LocalFile, "rb" )
          ??????? self.ftp.storbinary( 'STOR %s'%RemoteFile, file_handler, 4096 )
          ??????? file_handler.close()
          ??????? return True

          ??? def UpLoadFileTree( self, LocalDir, RemoteDir ):
          ??????? if os.path.isdir( LocalDir ) == False:
          ??????????? return False
          ??????? LocalNames = os.listdir( LocalDir )
          ??????? self.ftp.cwd( RemoteDir )
          ??????? for Local in LocalNames:
          ??????????? src = os.path.join( LocalDir, Local)
          ??????????? if os.path.isdir( src ):
          ??????????????? self.UpLoadFileTree( src, Local )
          ??????????? else:
          ??????????????? self.UpLoadFile( src, Local )
          ???????????????
          ??????? self.ftp.cwd( ".." )
          ??????? return
          ???
          ??? def DownLoadFileTree( self, LocalDir, RemoteDir ):
          ??????? if os.path.isdir( LocalDir ) == False:
          ??????????? os.makedirs( LocalDir )
          ??????? self.ftp.cwd( RemoteDir )
          ??????? RemoteNames = self.ftp.nlst()?
          ??????? for file in RemoteNames:
          ??????????? Local = os.path.join( LocalDir, file )
          ??????????? if self.isDir( file ):
          ??????????????? self.DownLoadFileTree( Local, file )???????????????
          ??????????? else:
          ??????????????? self.DownLoadFile( Local, file )
          ??????? self.ftp.cwd( ".." )
          ??????? return
          ???
          ??? def show( self, list? ):
          ??????? result = list.lower().split( " " )
          ??????? if self.path in result and "<dir>" in result:
          ??????????? self.bIsDir = True
          ????
          ??? def isDir( self, path ):
          ??????? self.bIsDir = False
          ??????? self.path = path
          ??????? #this ues callback function ,that will change bIsDir value
          ??????? self.ftp.retrlines( 'LIST', self.show )
          ??????? return self.bIsDir

          ftp = KANFtp('192.168.21.10')
          ftp.Login('XXX','XXXX')

          #ftp.DownLoadFile('TEST.TXT', 'public\\hechangmin\\TEST.TXT')#ok
          #ftp.UpLoadFile('TEST.TXT', 'public\\hechangmin\\TEST.TXT')#ok
          #ftp.DownLoadFileTree('HECM', 'public\\hechangmin\\xxx\\')#ok
          ftp.UpLoadFileTree('ts',"Public\\hechangmin\\testFTP" )
          print "ok!"

          這個是我同事代碼。我只是修改一小部分。本blog以流水賬形式記錄著學(xué)習(xí)的點點滴滴。

          posted on 2008-04-15 13:54 -274°C 閱讀(750) 評論(0)  編輯  收藏 所屬分類: python

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網(wǎng)站

          關(guān)注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 916109
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 中阳县| 赤壁市| 荣成市| 子洲县| 洪湖市| 苏尼特左旗| 平阴县| 花莲市| 惠水县| 香港 | 象山县| 夏津县| 肃宁县| 长泰县| 九寨沟县| 平罗县| 资源县| 重庆市| 太谷县| 左权县| 竹溪县| 鄄城县| 聊城市| 安陆市| 宿州市| 新巴尔虎右旗| 印江| 门头沟区| 札达县| 宜城市| 怀远县| 甘孜| 平江县| 手游| 涪陵区| 灌南县| 洛川县| 兴隆县| 丹棱县| 新源县| 阜城县|