Skip to content

Commit 839004f

Browse files
committed
Various changes to upload/download methods and other minor changes
1 parent ff6187d commit 839004f

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/SSHConnection.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,6 @@ private function sanityCheck()
6262
}
6363
}
6464

65-
public function upload(string $localPath, string $remotePath): bool
66-
{
67-
if (!is_resource($this->resource)) {
68-
throw new InvalidArgumentException('The session resource is invalid.');
69-
}
70-
71-
if (!file_exists($localPath)) {
72-
throw new InvalidArgumentException('The localPath is invalid.');
73-
}
74-
75-
return ssh2_scp_send($this->resource, $localPath, $remotePath);
76-
}
77-
78-
public function download(string $remotePath, string $localPath): bool
79-
{
80-
if (!is_resource($this->resource)) {
81-
throw new InvalidArgumentException('The session resource is invalid.');
82-
}
83-
84-
return ssh2_scp_recv($this->resource, $remotePath, $localPath);
85-
}
86-
8765
public function connect(): self
8866
{
8967
$this->sanityCheck();
@@ -109,7 +87,7 @@ public function connect(): self
10987
return $this;
11088
}
11189

112-
public function disconnect()
90+
public function disconnect(): void
11391
{
11492
if (!$this->connected) {
11593
throw new RuntimeException('Unable to disconnect. Not yet connected.');
@@ -118,12 +96,34 @@ public function disconnect()
11896
ssh2_disconnect($this->resource);
11997
}
12098

121-
public function run(string $command)
99+
public function run(string $command): SSHCommand
122100
{
123101
if (!$this->connected) {
124102
throw new RuntimeException('Unable to run commands when not connected.');
125103
}
126104

127105
return new SSHCommand($this->resource, $command);
128106
}
107+
108+
public function upload(string $localPath, string $remotePath): bool
109+
{
110+
if (!$this->connected) {
111+
throw new RuntimeException('Unable to upload file when not connected.');
112+
}
113+
114+
if (!file_exists($localPath)) {
115+
throw new InvalidArgumentException('The local file does not exist.');
116+
}
117+
118+
return ssh2_scp_send($this->resource, $localPath, $remotePath);
119+
}
120+
121+
public function download(string $remotePath, string $localPath): bool
122+
{
123+
if (!$this->connected) {
124+
throw new RuntimeException('Unable to download file when not connected.');
125+
}
126+
127+
return ssh2_scp_recv($this->resource, $remotePath, $localPath);
128+
}
129129
}

0 commit comments

Comments
 (0)