Skip to content

Commit 75a6f29

Browse files
committed
1 parent b94c87f commit 75a6f29

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

class-ftp-implicit-ssl-tls.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,58 @@ public function upload( $file_name, $file ) {
123123
fclose( $stream );
124124
}
125125

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+
126178
/**
127179
* Attempt to close cURL handle
128180
* Note - errors suppressed here as they are not useful

0 commit comments

Comments
 (0)