Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
8ecca2aa
Commit
8ecca2aa
authored
Feb 09, 2015
by
Alexander Golovko
Committed by
Mitchell Hashimoto
Jun 15, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement ssh.Download()
parent
6c1b6dbb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
2 deletions
+53
-2
communicator/ssh/communicator.go
communicator/ssh/communicator.go
+53
-2
No files found.
communicator/ssh/communicator.go
View file @
8ecca2aa
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"net"
"net"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"sync"
"sync"
)
)
...
@@ -171,8 +172,58 @@ func (c *comm) UploadDir(dst string, src string, excl []string) error {
...
@@ -171,8 +172,58 @@ func (c *comm) UploadDir(dst string, src string, excl []string) error {
return
c
.
scpSession
(
"scp -rvt "
+
dst
,
scpFunc
)
return
c
.
scpSession
(
"scp -rvt "
+
dst
,
scpFunc
)
}
}
func
(
c
*
comm
)
Download
(
string
,
io
.
Writer
)
error
{
func
(
c
*
comm
)
Download
(
path
string
,
output
io
.
Writer
)
error
{
panic
(
"not implemented yet"
)
scpFunc
:=
func
(
w
io
.
Writer
,
stdoutR
*
bufio
.
Reader
)
error
{
fmt
.
Fprint
(
w
,
"
\x00
"
)
// read file info
fi
,
err
:=
stdoutR
.
ReadString
(
'\n'
)
if
err
!=
nil
{
return
err
}
if
len
(
fi
)
<
0
{
return
fmt
.
Errorf
(
"empty response from server"
)
}
switch
fi
[
0
]
{
case
'\x01'
,
'\x02'
:
return
fmt
.
Errorf
(
"%s"
,
fi
[
1
:
len
(
fi
)])
case
'C'
:
case
'D'
:
return
fmt
.
Errorf
(
"remote file is directory"
)
default
:
return
fmt
.
Errorf
(
"unexpected server response (%x)"
,
fi
[
0
])
}
var
mode
string
var
size
int64
n
,
err
:=
fmt
.
Sscanf
(
fi
,
"%6s %d "
,
&
mode
,
&
size
)
if
err
!=
nil
||
n
!=
2
{
return
fmt
.
Errorf
(
"can't parse server response (%s)"
,
fi
)
}
if
size
<
0
{
return
fmt
.
Errorf
(
"negative file size"
)
}
fmt
.
Fprint
(
w
,
"
\x00
"
)
if
_
,
err
:=
io
.
CopyN
(
output
,
stdoutR
,
size
);
err
!=
nil
{
return
err
}
fmt
.
Fprint
(
w
,
"
\x00
"
)
if
err
:=
checkSCPStatus
(
stdoutR
);
err
!=
nil
{
return
err
}
return
nil
}
return
c
.
scpSession
(
"scp -vf "
+
strconv
.
Quote
(
path
),
scpFunc
)
}
}
func
(
c
*
comm
)
newSession
()
(
session
*
ssh
.
Session
,
err
error
)
{
func
(
c
*
comm
)
newSession
()
(
session
*
ssh
.
Session
,
err
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment