TeamSpeak 3 PHP Framework
Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
TeamSpeak3_Adapter_FileTransfer Class Reference

Provides low-level methods for file transfer communication with a TeamSpeak 3 Server. More...

+ Inheritance diagram for TeamSpeak3_Adapter_FileTransfer:

Public Member Functions

 __destruct ()
 The TeamSpeak3_Adapter_FileTransfer destructor. More...
 
 download ($ftkey, $size, $passthru=FALSE)
 Returns the content of a downloaded file as a TeamSpeak3_Helper_String object. More...
 
 syn ()
 Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server. More...
 
 upload ($ftkey, $seek, $data)
 Sends the content of a file to the server. More...
 
- Public Member Functions inherited from TeamSpeak3_Adapter_Abstract
 __construct (array $options)
 The TeamSpeak3_Adapter_Abstract constructor. More...
 
 __destruct ()
 The TeamSpeak3_Adapter_Abstract destructor. More...
 
 __sleep ()
 Commit pending data. More...
 
 __wakeup ()
 Reconnects to the remote server. More...
 
 getProfiler ()
 Returns the profiler timer used for this connection adapter. More...
 
 getTransport ()
 Returns the transport object used for this connection adapter. More...
 
 getTransportHost ()
 Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object is connected to. More...
 
 getTransportPort ()
 Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object is connected to. More...
 

Protected Member Functions

 init ($ftkey)
 Sends a valid file transfer key to the server to initialize the file transfer. More...
 
 passthru ($size)
 Outputs all remaining data on a TeamSpeak 3 file transfer stream using PHP's fpassthru() function. More...
 
- Protected Member Functions inherited from TeamSpeak3_Adapter_Abstract
 initTransport ($options, $transport="TeamSpeak3_Transport_TCP")
 Loads the transport object object used for the connection adapter and passes a given set of options. More...
 
 syn ()
 Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server. More...
 

Detailed Description

Provides low-level methods for file transfer communication with a TeamSpeak 3 Server.

Constructor & Destructor Documentation

◆ __destruct()

__destruct ( )

The TeamSpeak3_Adapter_FileTransfer destructor.

Returns
void
54  {
55  if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->getTransport()->isConnected())
56  {
57  $this->getTransport()->disconnect();
58  }
59  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
Abstract class for connecting to a TeamSpeak 3 Server through different ways of transport.
Definition: Abstract.php:29

Member Function Documentation

◆ download()

download (   $ftkey,
  $size,
  $passthru = FALSE 
)

Returns the content of a downloaded file as a TeamSpeak3_Helper_String object.

Parameters
string$ftkey
integer$size
boolean$passthru
Exceptions
TeamSpeak3_Adapter_FileTransfer_Exception
Returns
TeamSpeak3_Helper_String
132  {
133  $this->init($ftkey);
134 
135  if($passthru)
136  {
137  return $this->passthru($size);
138  }
139 
140  $buff = new TeamSpeak3_Helper_String("");
141  $size = intval($size);
142  $pack = 4096;
143 
144  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadStarted", $ftkey, count($buff), $size);
145 
146  for($seek = 0;$seek < $size;)
147  {
148  $rest = $size-$seek;
149  $pack = $rest < $pack ? $rest : $pack;
150  $data = $this->getTransport()->read($rest < $pack ? $rest : $pack);
151  $seek = $seek+$pack;
152 
153  $buff->append($data);
154 
155  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadProgress", $ftkey, count($buff), $size);
156  }
157 
158  $this->getProfiler()->stop();
159 
160  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferDownloadFinished", $ftkey, count($buff), $size);
161 
162  if(strlen($buff) != $size)
163  {
164  throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . count($buff) . " of " . $size . " bytes)");
165  }
166 
167  return $buff;
168  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
Helper class for string handling.
Definition: String.php:29
passthru($size)
Outputs all remaining data on a TeamSpeak 3 file transfer stream using PHP&#39;s fpassthru() function...
Definition: FileTransfer.php:178
Enhanced exception class for TeamSpeak3_Adapter_FileTransfer objects.
Definition: Exception.php:29
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
init($ftkey)
Sends a valid file transfer key to the server to initialize the file transfer.
Definition: FileTransfer.php:68
getProfiler()
Returns the profiler timer used for this connection adapter.
Definition: Abstract.php:102

◆ init()

init (   $ftkey)
protected

Sends a valid file transfer key to the server to initialize the file transfer.

Parameters
string$ftkey
Exceptions
TeamSpeak3_Adapter_FileTransfer_Exception
Returns
void
69  {
70  if(strlen($ftkey) != 32 && strlen($ftkey) != 16)
71  {
72  throw new TeamSpeak3_Adapter_FileTransfer_Exception("invalid file transfer key format");
73  }
74 
75  $this->getProfiler()->start();
76  $this->getTransport()->send($ftkey);
77 
78  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferHandshake", $this);
79  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
Enhanced exception class for TeamSpeak3_Adapter_FileTransfer objects.
Definition: Exception.php:29
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
getProfiler()
Returns the profiler timer used for this connection adapter.
Definition: Abstract.php:102

◆ passthru()

passthru (   $size)
protected

Outputs all remaining data on a TeamSpeak 3 file transfer stream using PHP's fpassthru() function.

Parameters
integer$size
Exceptions
TeamSpeak3_Adapter_FileTransfer_Exception
Returns
void
179  {
180  $buff_size = fpassthru($this->getTransport()->getStream());
181 
182  if($buff_size != $size)
183  {
184  throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file download (" . intval($buff_size) . " of " . $size . " bytes)");
185  }
186  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
Enhanced exception class for TeamSpeak3_Adapter_FileTransfer objects.
Definition: Exception.php:29

◆ syn()

syn ( )

Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server.

Exceptions
TeamSpeak3_Adapter_Exception
Returns
void
39  {
40  $this->initTransport($this->options);
41  $this->transport->setAdapter($this);
42 
43  TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));
44 
45  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferConnected", $this);
46  }
static init($name="default")
Inits a timer.
Definition: Profiler.php:44
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
initTransport($options, $transport="TeamSpeak3_Transport_TCP")
Loads the transport object object used for the connection adapter and passes a given set of options...
Definition: Abstract.php:126

◆ upload()

upload (   $ftkey,
  $seek,
  $data 
)

Sends the content of a file to the server.

Parameters
string$ftkey
integer$seek
string$data
Exceptions
TeamSpeak3_Adapter_FileTransfer_Exception
Returns
void
91  {
92  $this->init($ftkey);
93 
94  $size = strlen($data);
95  $seek = intval($seek);
96  $pack = 4096;
97 
98  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadStarted", $ftkey, $seek, $size);
99 
100  for(;$seek < $size;)
101  {
102  $rest = $size-$seek;
103  $pack = $rest < $pack ? $rest : $pack;
104  $buff = substr($data, $seek, $pack);
105  $seek = $seek+$pack;
106 
107  $this->getTransport()->send($buff);
108 
109  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadProgress", $ftkey, $seek, $size);
110  }
111 
112  $this->getProfiler()->stop();
113 
114  TeamSpeak3_Helper_Signal::getInstance()->emit("filetransferUploadFinished", $ftkey, $seek, $size);
115 
116  if($seek < $size)
117  {
118  throw new TeamSpeak3_Adapter_FileTransfer_Exception("incomplete file upload (" . $seek . " of " . $size . " bytes)");
119  }
120  }
getTransport()
Returns the transport object used for this connection adapter.
Definition: Abstract.php:112
Enhanced exception class for TeamSpeak3_Adapter_FileTransfer objects.
Definition: Exception.php:29
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
init($ftkey)
Sends a valid file transfer key to the server to initialize the file transfer.
Definition: FileTransfer.php:68
getProfiler()
Returns the profiler timer used for this connection adapter.
Definition: Abstract.php:102

The documentation for this class was generated from the following file: