-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate_ftp.R
executable file
·131 lines (106 loc) · 6.27 KB
/
update_ftp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
library(raster)
library(dplyr)
library(RCurl)
library(lubridate)
library(stringr)
refresh_ftp = function(){
ftp = "ftp://publi_dgh2:[email protected]/PISCOp_V2.1_beta/"
#Copy the R.data
name = "/home/senamhi-cesar/PISCO/PISCOpV2.1/PISCOp_raingauge_database.Rdata"
ftp_name = sprintf("%s/%s",ftp,basename(name))
ftpUpload(name,ftp_name)
# Copy monthly
name_com = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Monthly_Products/unstable/Unstable_Monthly_gaugecomplete_Dataset.csv"
ftp_name_com = sprintf("%s/Monthly_Products/unstable/%s",ftp,basename(name_com))
ftpUpload(name_com,ftp_name_com)
name_raw = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Monthly_Products/unstable/Unstable_Monthly_gaugeraw_Dataset.csv"
ftp_name_raw = sprintf("%s/Monthly_Products/unstable/%s",ftp,basename(name_raw))
ftpUpload(name_raw,ftp_name_raw)
# Copy daily
name_com = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Daily_Products/unstable/Unstable_Daily_gaugecomplete_Dataset.csv"
ftp_name_com = sprintf("%s/Daily_Products/unstable/%s",ftp,basename(name_com))
ftpUpload(name_com,ftp_name_com)
name_raw = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Daily_Products/unstable/Unstable_Daily_gaugeraw_Dataset.csv"
ftp_name_raw = sprintf("%s/Daily_Products/unstable/%s",ftp,basename(name_raw))
ftpUpload(name_raw,ftp_name_raw)
### CHIRPMm
CHIRPm = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Monthly_Products/unstable/CHIRPMm"
dd = list.files(CHIRPm,full.names = T)
dates_home = gsub("CHIRPMm.","",basename(dd)) %>% gsub(".tif","",.) %>% as.Date()
chirpMm = "ftp://publi_dgh2:[email protected]/PISCOp_V2.1_beta/Monthly_Products/unstable/CHIRPMm/"
filenames <- getURL(chirpMm, ftp.use.epsv = FALSE, ftplistonly=TRUE, crlf=TRUE)
filePaths <- strsplit(filenames, "*\n")[[1]]
dates_server = filePaths %>% sub("CHIRPMm.","",.) %>% sub(".tif","",.) %>% as.Date()
stdff = setdiff(dates_home,dates_server) %>% as.Date(.,origin=as.Date("1970-01-01"))
lost_files = which(dates_home %in% stdff)
if(length(lost_files)>0){
message("Completando el ftp ... CHIRPMm")
basename_CHIRPMm = dd[lost_files]
ftpname_CHIRPMm = sprintf("%s/Monthly_Products/unstable/CHIRPMm/%s",ftp,basename(dd[lost_files]))
mapply(function(i) ftpUpload(basename_CHIRPMm[i],ftpname_CHIRPMm[i]), 1:length(basename_CHIRPMm))
}
### PISCOpm
CHIRPm = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Monthly_Products/unstable/PISCOpm/"
dd = list.files(CHIRPm,full.names = T)
dates_home = gsub("PISCOpm_V2.1.","",basename(dd)) %>% gsub(".tif","",.) %>% as.Date()
chirpMm = "ftp://publi_dgh2:[email protected]/PISCOp_V2.1_beta/Monthly_Products/unstable/PISCOpm/"
filenames <- getURL(chirpMm, ftp.use.epsv = FALSE, ftplistonly=TRUE, crlf=TRUE)
filePaths <- strsplit(filenames, "*\n")[[1]]
dates_server = filePaths %>% sub("PISCOpm_V2.1.","",.) %>% sub(".tif","",.) %>% as.Date()
stdff = setdiff(dates_home,dates_server) %>% as.Date(.,origin=as.Date("1970-01-01"))
lost_files = which(dates_home %in% stdff)
if(length(lost_files)>0){
message("Completando el ftp ... PISCOpm")
basename_CHIRPMm = dd[lost_files]
ftpname_CHIRPMm = sprintf("%s/Monthly_Products/unstable/PISCOpm/%s",ftp,basename(dd[lost_files]))
mapply(function(i) ftpUpload(basename_CHIRPMm[i],ftpname_CHIRPMm[i]), 1:length(basename_CHIRPMm))
}
### CHIRPMd
CHIRPm = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Daily_Products/unstable/CHIRPMd/"
dd = list.files(CHIRPm,full.names = T)
dates_home = gsub("CHIRPMd.","",basename(dd)) %>% gsub(".tif","",.) %>% as.Date()
chirpMm = "ftp://publi_dgh2:[email protected]/PISCOp_V2.1_beta/Daily_Products/unstable/CHIRPMd/"
filenames <- getURL(chirpMm, ftp.use.epsv = FALSE, ftplistonly=TRUE, crlf=TRUE)
filePaths <- strsplit(filenames, "*\n")[[1]]
dates_server = filePaths %>% sub("CHIRPMd.","",.) %>% sub(".tif","",.) %>% as.Date()
stdff = setdiff(dates_home,dates_server) %>% as.Date(.,origin=as.Date("1970-01-01"))
lost_files = which(dates_home %in% stdff)
if(length(lost_files)>0){
message("Completando el ftp ... CHIRPMd")
basename_CHIRPMm = dd[lost_files]
ftpname_CHIRPMm = sprintf("%s/Daily_Products/unstable/CHIRPMd/%s",ftp,basename(dd[lost_files]))
mapply(function(i) ftpUpload(basename_CHIRPMm[i],ftpname_CHIRPMm[i]), 1:length(basename_CHIRPMm))
}
### PISCOpd
CHIRPm = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Daily_Products/unstable/PISCOpd/"
dd = list.files(CHIRPm,full.names = T)
dates_home = gsub("PISCOpd_V2.1.","",basename(dd)) %>% gsub(".tif","",.) %>% as.Date()
chirpMm = "ftp://publi_dgh2:[email protected]/PISCOp_V2.1_beta/Daily_Products/unstable/PISCOpd/"
filenames <- getURL(chirpMm, ftp.use.epsv = FALSE, ftplistonly=TRUE, crlf=TRUE)
filePaths <- strsplit(filenames, "*\n")[[1]]
dates_server = filePaths %>% sub("PISCOpd_V2.1.","",.) %>% sub(".tif","",.) %>% as.Date()
stdff = setdiff(dates_home,dates_server) %>% as.Date(.,origin=as.Date("1970-01-01"))
lost_files = which(dates_home %in% stdff)
if(length(lost_files)>0){
message("Completando el ftp ... PISCOpd")
basename_CHIRPMm = dd[lost_files]
ftpname_CHIRPMm = sprintf("%s/Daily_Products/unstable/PISCOpd/%s",ftp,basename(dd[lost_files]))
mapply(function(i) ftpUpload(basename_CHIRPMm[i],ftpname_CHIRPMm[i]), 1:length(basename_CHIRPMm))
}
### P-PISCOpd
CHIRPm = "/home/senamhi-cesar/PISCO/PISCOpV2.1/Daily_Products/unstable/P-PISCOpd/"
dd = list.files(CHIRPm,full.names = T)
dates_home = gsub("P-PISCOpd_V2.1.","",basename(dd)) %>% gsub(".tif","",.) %>% as.Date()
chirpMm = "ftp://publi_dgh2:[email protected]/PISCOp_V2.1_beta/Daily_Products/unstable/P-PISCOpd/"
filenames <- getURL(chirpMm, ftp.use.epsv = FALSE, ftplistonly=TRUE, crlf=TRUE)
filePaths <- strsplit(filenames, "*\n")[[1]]
dates_server = filePaths %>% sub("P-PISCOpd_V2.1.","",.) %>% sub(".tif","",.) %>% as.Date()
stdff = setdiff(dates_home,dates_server) %>% as.Date(.,origin=as.Date("1970-01-01"))
lost_files = which(dates_home %in% stdff)
if(length(lost_files)>0){
message("Completando el ftp ... P-PISCOpd")
basename_CHIRPMm = dd[lost_files]
ftpname_CHIRPMm = sprintf("%s/Daily_Products/unstable/P-PISCOpd/%s",ftp,basename(dd[lost_files]))
mapply(function(i) ftpUpload(basename_CHIRPMm[i],ftpname_CHIRPMm[i]), 1:length(basename_CHIRPMm))
}
}