Пример #1
0
 def download(self):
   self.pingServer(message=False)
   if self.connected:
     overwrite = False
     pathExists = False
     target = getSingleActionParam(act["Download"], self.action)
     targetPath = getNextPath(self.pathRemote, target)
     absTargetPath, targetName = os.path.split(targetPath)
     localTargetPath = getNextPath(self.pathLocal, targetName)
     if self.ftp.exists(targetName, absTargetPath):
       if os.path.exists(localTargetPath):
         pathExists = True
         confirmOverwrite = interact.confirm(ns.interact["data_exists"].format(target=targetName))
         if confirmOverwrite:
           overwrite = True
       downloadingMsg = ns.common["downloading"].format(target=targetPath)
       try:
         spinner.start(downloadingMsg)
         if self.ftp.isDir(targetPath):
           self.ftp.getTree(targetPath, pathExists, overwrite)
         else:
           self.ftp.getFile(targetPath, self.pathLocal, pathExists, overwrite)
         spinner.success(downloadingMsg)
         msg.success(ns.common["success"])
       except Exception as e:
         spinner.fail(downloadingMsg)
         msg.default(e)
         msg.error(ns.errors["transfer_error"])
     else:
       msg.error(ns.errors["invalid_path"])
   else:
     msg.error(ns.errors["no_connection"])
Пример #2
0
 def connect(self):
   hostStr = getSingleActionParam(act["Connect"], self.action)
   loginStr = ns.common["login"]["user"]
   passwdStr = ns.common["login"]["passwd"]
   portSrt = ns.common["login"]["port"]
   userInput = interact.multiInput([loginStr, passwdStr, portSrt])
   self.loginData = {
     "host": hostStr,
     "user": userInput[loginStr],
     "passwd": userInput[passwdStr],
     "port": userInput[portSrt] or settings["ftp"]["port"]
   }
   connectingMsg = ns.common["connecting"].format(host=self.loginData["host"])
   connectedMsg = ns.common["connected"].format(host=self.loginData["host"])
   errorMsg = ns.errors["connecting_error"].format(host=self.loginData["host"])
   spinner.start(connectingMsg)
   try:
     isConnected = self.login()
     if isConnected:
       spinner.success(connectingMsg)
       msg.default(self.ftp.getwelcome())
       msg.success(connectedMsg)
   except Exception as e:
     spinner.fail(connectingMsg)
     self.setStatusDisconnected()
     msg.default(e)
     msg.error(errorMsg)
Пример #3
0
 def changeEnv(self):
   changeTo = getSingleActionParam(act["ChangeEnv"], self.action)
   if changeTo == envs["Local"]:
     self.env = envs["Local"]
   else:
     self.pingServer()
     if self.connected:
       self.env = envs["Remote"]
Пример #4
0
 def mkdir(self):
   dirName = getSingleActionParam(act["Mkdir"], self.action)
   try:
     if self.env == envs["Local"]:
       localDirPath = getNextPath(self.pathLocal, dirName)
       os.mkdir(localDirPath)
     else:
       self.pingServer()
       if self.connected:
         remoteDirPath = getNextPath(self.pathRemote, dirName)
         self.ftp.mkd(remoteDirPath)
   except Exception as e:
     msg.default(e)
     msg.error(ns.errors["mkdir_error"].format(dirName=dirName))
Пример #5
0
 def cd(self):
   dest = getSingleActionParam(act["Cd"], self.action)
   if self.env == envs["Local"]:
     nextLocalPath = getNextPath(self.pathLocal, dest)
     if os.path.exists(nextLocalPath):
       self.changeLocalPath(nextLocalPath)  
     else:
       msg.error(ns.errors["cd_error"].format(dest=nextLocalPath))
   else:
     self.pingServer()
     if self.connected:
       try:
         nextRemotePath = getNextPath(self.pathRemote, dest)
         self.changeRemotePath(nextRemotePath)
       except Exception as e:
         msg.default(e)
         msg.error(ns.errors["cd_error"].format(dest=nextRemotePath))
Пример #6
0
 def delete(self):
   target = getSingleActionParam(act["Delete"], self.action)
   try:
     if self.env == envs["Local"]:
       localTargetPath = getNextPath(self.pathLocal, target)  
       if os.path.exists(localTargetPath):
         deletingMsg = ns.common["deleting"].format(target=localTargetPath)  
         confirmMsg = ns.interact["confirm_delete"].format(fileName=localTargetPath)
         confirmDel = interact.confirm(confirmMsg)  
         if confirmDel:
           spinner.start(deletingMsg)
           if os.path.isdir(localTargetPath):
             shutil.rmtree(localTargetPath)
           else:
             os.remove(localTargetPath)
           spinner.success(deletingMsg)
           msg.success(ns.common["success"])
       else:
         msg.error(ns.errors["invalid_path"])
     else:
       self.pingServer()
       if self.connected:
         remoteTargetPath = getNextPath(self.pathRemote, target)
         absTargetPath, absTargetName = os.path.split(remoteTargetPath)
         if self.ftp.exists(absTargetName, absTargetPath):
           deletingMsg = ns.common["deleting"].format(target=remoteTargetPath)  
           confirmMsg = ns.interact["confirm_delete"].format(fileName=remoteTargetPath)
           confirmDel = interact.confirm(confirmMsg)  
           if confirmDel:
             spinner.start(deletingMsg)
             if self.ftp.isDir(remoteTargetPath):
               self.ftp.rmTree(remoteTargetPath)
             else:
               self.ftp.delete(remoteTargetPath)
             spinner.success(deletingMsg)
             msg.success(ns.common["success"])
         else:
           msg.error(ns.errors["invalid_path"])
   except Exception as e:
     spinner.fail(deletingMsg)
     msg.default(e)
     msg.error(ns.errors["delete_error"].format(target=target))