##// END OF EJS Templates
FTP modificado, para usarse libremente (no schain) y subir rti de AMISR a jro-app, ventaja de usar esta clase antigua solo se sube un archivo una vez finalizado el procesamiento offline.
joabAM -
r1422:161fd8f163b6
parent child
Show More
@@ -640,6 +640,7 class Project(Process):
640 640 #print("CONF: ",conf)
641 641 ok = conf.run()
642 642 if ok == 'Error':
643 #self.removeProcUnit(conf.id) #remove proc Unit
643 644 n -= 1
644 645 continue
645 646 elif not ok:
@@ -651,6 +651,8 class HDFWrite(Operation):
651 651 #Write data
652 652 self.writeData(self.fp)
653 653 log.log('Block No. {}/{} --> {}'.format(self.blockIndex+1, self.blocksPerFile,self.dataOut.datatime.ctime()), self.name)
654 elif (self.blockIndex % 10 ==0):
655 log.log('Block No. {}/{} --> {}'.format(self.blockIndex+1, self.blocksPerFile,self.dataOut.datatime.ctime()), self.name)
654 656 else:
655 657
656 658 log.log('Block No. {}/{}'.format(self.blockIndex+1, self.blocksPerFile), self.name)
@@ -769,6 +769,9 class FTP(object):
769 769 Non-standard Python modules used: None
770 770
771 771 Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010
772
773 Modified:
774 Joab Apaza Feb. 2022
772 775 """
773 776
774 777 def __init__(self,server = None, username=None, password=None, remotefolder=None):
@@ -868,9 +871,9 class FTP(object):
868 871 self.ftp.mkd(dirname)
869 872 except:
870 873 print('Error creating remote folder:%s'%dirname)
871 return 1
874 return False
872 875
873 return 0
876 return True
874 877
875 878
876 879 def delete(self,filename):
@@ -888,9 +891,9 class FTP(object):
888 891 self.ftp.delete(filename)
889 892 except:
890 893 print('Error deleting remote file:%s'%filename)
891 return 1
894 return False
892 895
893 return 0
896 return True
894 897
895 898 def download(self,filename,localfolder):
896 899 """
@@ -938,15 +941,17 class FTP(object):
938 941 self.file.write(block)
939 942
940 943
941 def upload(self,filename,remotefolder=None):
944 def upload(self,filename,remotefolder=None, mkdir=False):
942 945 """
943 upload is used to uploading local file to remote directory
946 upload is used to uploading local file to remote directory, and change the permission of the remote file
944 947
945 948 Inputs:
946 949 filename - full path name of local file to store in remote directory
947 950
948 951 remotefolder - remote directory
949 952
953 mkdir - if the remote folder doesn't exist, it will created
954
950 955 Returns:
951 956 self.status - 1 in error case else 0
952 957 """
@@ -954,6 +959,12 class FTP(object):
954 959 if remotefolder == None:
955 960 remotefolder = self.remotefolder
956 961
962 if mkdir:
963 if self.if_dir_exist(remotefolder):
964 pass
965 else:
966 self.mkdir_r(remotefolder)
967
957 968 self.status = 0
958 969
959 970 try:
@@ -967,6 +978,7 class FTP(object):
967 978
968 979 print('Uploading: ' + tail)
969 980 self.ftp.storbinary(command, self.file)
981 print(self.cmd('SITE CHMOD 755 {}'.format(tail)))
970 982 print('Upload Completed')
971 983
972 984 except ftplib.all_errors:
@@ -982,9 +994,9 class FTP(object):
982 994 return self.status
983 995
984 996
985 def dir(self,remotefolder):
997 def ch_dir(self,remotefolder):
986 998 """
987 dir is used to change working directory of remote server and get folder and file list
999 ch_dir is used to change working directory of remote server and get folder and file list
988 1000
989 1001 Input:
990 1002 remotefolder - current working directory
@@ -1039,8 +1051,6 class FTP(object):
1039 1051 self.folderList.append(f)
1040 1052
1041 1053 return infoList,self.folderList
1042
1043
1044 1054 def close(self):
1045 1055 """
1046 1056 close is used to close and end FTP connection
@@ -1051,6 +1061,85 class FTP(object):
1051 1061
1052 1062 """
1053 1063 self.ftp.close()
1064
1065 def get_sub_dirs(self, path):
1066 """
1067 used internal
1068
1069 Inputs:
1070 path - path to split in sub folders
1071
1072 Returns:
1073 sub_dirs - list of sub folders
1074 """
1075 sub_dirs = path.split("/")
1076 if sub_dirs[0]=="/":
1077 sub_dirs.pop(0)
1078 if sub_dirs[-1]=="/":
1079 sub_dirs.pop(-1)
1080 return sub_dirs
1081
1082 def if_dir_exist(self,path):
1083 """
1084 check if a the path folder exists in the ftp server
1085
1086 Inputs:
1087 path - path to check
1088
1089 Returns:
1090 status - True if exists and False if it doesn't
1091 """
1092 sub_dirs = self.get_sub_dirs(path)
1093 main = self.ftp.pwd()
1094 #print(main)
1095 for subdir in sub_dirs:
1096 folders = self.ftp.nlst(main)
1097 #print(folders)
1098 if (os.path.join(main,subdir) in folders):
1099 main = os.path.join(main,subdir)
1100 #print(main)
1101 continue
1102 else:
1103 return False
1104 return True
1105
1106 def cmd(self,command):
1107 """
1108 excecute a command in the FTP server
1109 """
1110 return self.ftp.sendcmd(command)
1111
1112 def mkdir_r(self,path):
1113 """
1114 create a remote folder and create sub folders if it is necessary
1115
1116 Inputs:
1117 path - path to create
1118
1119 Returns:
1120 status - True if succesfull else False
1121 """
1122 sub_dirs = self.get_sub_dirs(path)
1123 main = self.ftp.pwd()
1124 st = False
1125 #print(main)
1126 for subdir in sub_dirs:
1127 folders = self.ftp.nlst(main)
1128 #print(folders)
1129 folder = (os.path.join(main,subdir))
1130
1131 if (folder in folders):
1132 main = folder
1133 #print("new_main",main)
1134 continue
1135 else:
1136 print("creating...",folder)
1137 st = self.mkd(folder)
1138 print(self.cmd('SITE CHMOD 755 {}'.format(folder)))
1139 main = folder
1140
1141 return st
1142
1054 1143 @MPDecorator
1055 1144 class SendByFTP(Operation):
1056 1145
General Comments 0
You need to be logged in to leave comments. Login now