Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bruce Flynn
sftper
Commits
c41992b3
Commit
c41992b3
authored
Oct 11, 2019
by
Bruce Flynn
Browse files
print debug throughput for GET as well as PUT
parent
a467b74b
Changes
1
Hide whitespace changes
Inline
Side-by-side
api.go
View file @
c41992b3
...
...
@@ -183,6 +183,17 @@ func (s sftpAPI) rempath(path string) string {
return
path
}
// debug print throughput numbers
func
throughput
(
fcn
func
()
(
int64
,
error
))
(
int64
,
error
)
{
t
:=
time
.
Now
()
n
,
err
:=
fcn
()
if
err
==
nil
{
tt
:=
time
.
Now
()
.
Sub
(
t
)
.
Seconds
()
debug
(
"%fs, %d bytes; throughput %f Mb/s"
,
tt
,
n
,
float64
(
n
)
*
8
/
1024
/
1024
/
tt
)
}
return
n
,
err
}
// args: source, dest as abs paths
func
(
s
sftpAPI
)
doPut
(
source
,
dest
string
)
error
{
dest
=
s
.
rempath
(
dest
)
...
...
@@ -198,13 +209,12 @@ func (s sftpAPI) doPut(source, dest string) error {
}
defer
fin
.
Close
()
t
:=
time
.
Now
()
n
,
err
:=
io
.
Copy
(
fout
,
fin
)
_
,
err
=
throughput
(
func
()
(
int64
,
error
)
{
return
io
.
Copy
(
fout
,
fin
)
})
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"upload failed for %s -> %s"
,
source
,
dest
)
}
tt
:=
time
.
Now
()
.
Sub
(
t
)
.
Seconds
()
debug
(
"%fs, %d bytes; throughput %f Mb/s"
,
tt
,
n
,
float64
(
n
)
*
8
/
1024
/
1024
/
tt
)
return
nil
}
...
...
@@ -224,7 +234,9 @@ func (s sftpAPI) doGet(source, dest string) error {
}
defer
fout
.
Close
()
_
,
err
=
io
.
Copy
(
fout
,
fin
)
_
,
err
=
throughput
(
func
()
(
int64
,
error
)
{
return
io
.
Copy
(
fout
,
fin
)
})
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"download failed for %s -> %s"
,
source
,
dest
)
}
...
...
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