@@ -123,6 +123,58 @@ public function upload( $file_name, $file ) {
123
123
fclose ( $ stream );
124
124
}
125
125
126
+ /**
127
+ * @return array of file names
128
+ * @throws Exception
129
+ */
130
+ public function ftpfilelist (){
131
+ if ( ! curl_setopt ( $ this ->curl_handle , CURLOPT_URL , $ this ->url ))
132
+ throw new Exception ("Could not set cURL directory: $ this ->url " );
133
+ curl_setopt ( $ this ->curl_handle , CURLOPT_UPLOAD , false );
134
+ curl_setopt ( $ this ->curl_handle ,CURLOPT_FTPLISTONLY ,1 );
135
+ curl_setopt ( $ this ->curl_handle , CURLOPT_RETURNTRANSFER , 1 );
136
+ $ result = curl_exec ( $ this ->curl_handle ) or die ( curl_error ( $ this ->curl_handle ));
137
+ $ files = explode ("\n" ,trim ($ result ));
138
+ if ( count ($ files ) ){
139
+ return $ files ;
140
+ } else {
141
+ return array ();
142
+ }
143
+ }
144
+ /**
145
+ * Download remote file to the given location
146
+ */
147
+ public function download ($ file_name ,$ local_path ='/ ' ){
148
+ $ file = fopen ("$ local_path$ file_name " , "w " );
149
+ curl_setopt ( $ this ->curl_handle , CURLOPT_URL , $ this ->url . $ file_name );
150
+ curl_setopt ( $ this ->curl_handle , CURLOPT_UPLOAD , false );
151
+ curl_setopt ( $ this ->curl_handle , CURLOPT_FOLLOWLOCATION , 1 );
152
+ curl_setopt ( $ this ->curl_handle , CURLOPT_RETURNTRANSFER , 1 );
153
+ curl_setopt ( $ this ->curl_handle , CURLOPT_FILE , $ file );
154
+ $ result = curl_exec ($ this ->curl_handle );
155
+ fclose ($ file );
156
+ if ( strlen ($ result ) ){
157
+ return $ result ;
158
+ } else {
159
+ return "" ;
160
+ }
161
+ }
162
+ /**
163
+ * Get remote file size
164
+ * This will help to create a progress bar
165
+ */
166
+ public function remote_file_size ($ file_name ){
167
+ $ size =0 ;
168
+ curl_setopt ( $ this ->curl_handle , CURLOPT_URL , $ this ->url . $ file_name );
169
+ curl_setopt ( $ this ->curl_handle , CURLOPT_UPLOAD , false );
170
+ curl_setopt ( $ this ->curl_handle , CURLOPT_RETURNTRANSFER , TRUE );
171
+ curl_setopt ( $ this ->curl_handle , CURLOPT_HEADER , TRUE );
172
+ curl_setopt ( $ this ->curl_handle , CURLOPT_NOBODY , TRUE );
173
+ $ data = curl_exec ( $ this ->curl_handle );
174
+ $ size = curl_getinfo ( $ this ->curl_handle , CURLINFO_CONTENT_LENGTH_DOWNLOAD );
175
+ return $ size ;
176
+ }
177
+
126
178
/**
127
179
* Attempt to close cURL handle
128
180
* Note - errors suppressed here as they are not useful
0 commit comments