Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
60ca370
Add file transfer handlers for Connect
gzdunek Sep 30, 2022
b180eae
Allow callers to specify their own progress writers
gzdunek Sep 30, 2022
ec341f7
Generate protobuf files
gzdunek Sep 30, 2022
8d8f7e4
Fix imports order
gzdunek Oct 4, 2022
0784e0f
Update comments
gzdunek Oct 4, 2022
02a1970
Remove unnecessary condition
gzdunek Oct 4, 2022
3667888
Handle default enum value
gzdunek Oct 4, 2022
67a508b
Generate protobuf files
gzdunek Oct 4, 2022
8c282c0
Remove extra line and fix imports
gzdunek Oct 4, 2022
56372d4
Wrap `TransferFile` function body in `addMetadataToRetryableError`
gzdunek Oct 5, 2022
1de84e7
Use `hostname` instead of `serverUri`
gzdunek Oct 5, 2022
c74b4b9
Generate protobuf files
gzdunek Oct 5, 2022
130524c
Use shorter name for the receiver
gzdunek Oct 5, 2022
f5d19a1
Move `CreateProgressBar` to `sftp.go`
gzdunek Oct 6, 2022
96f0d01
Add lock to `Write`, `trace.Wrap` to error
gzdunek Oct 6, 2022
e9889e1
Bring back `NewProgressBar`
gzdunek Oct 6, 2022
95fcd02
Remove named exports, change `writeErr` to `err`, `canSendProgress` t…
gzdunek Oct 6, 2022
5d4ecf3
Instead of entire `TransferFileServer` pass `sendProgress` callback t…
gzdunek Oct 6, 2022
7c32cdf
Rename `GrpcFileTransferProgress` to `fileTransferProgress`
gzdunek Oct 6, 2022
7a1594f
Crate `FileTransferProgressSender` type
gzdunek Oct 7, 2022
915852d
Add comments to proto file
gzdunek Oct 10, 2022
fad9500
Move enum to switch/case statement
gzdunek Oct 10, 2022
d7e1345
Generate protobuf files
gzdunek Oct 10, 2022
520cf94
Merge branch 'branch/v11' into bot/backport-16880-branch/v11
gzdunek Oct 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,9 @@ func (tc *TeleportClient) SFTP(ctx context.Context, args []string, port int, opt
}

if !quiet {
config.cfg.ProgressWriter = tc.Stdout
config.cfg.ProgressWriter = func(fileInfo os.FileInfo) io.Writer {
return sftp.NewProgressBar(fileInfo.Size(), fileInfo.Name(), tc.Stdout)
}
}

return trace.Wrap(tc.TransferFiles(ctx, config.hostLogin, config.addr, config.cfg))
Expand Down
11 changes: 5 additions & 6 deletions lib/sshutils/sftp/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ type Config struct {
// SSH session
getHomeDir homeDirRetriever

// ProgressWriter is a writer for printing the progress
// ProgressWriter is a callback to return a writer for printing the progress
// (used only on the client)
ProgressWriter io.Writer
ProgressWriter func(fileInfo os.FileInfo) io.Writer
// Log optionally specifies the logger
Log log.FieldLogger
}
Expand Down Expand Up @@ -394,8 +394,7 @@ func (c *Config) transferFile(ctx context.Context, dstPath, srcPath string, srcF
}
// if a progress writer was set, write file transfer progress
if c.ProgressWriter != nil {
progressBar := newProgressBar(srcFileInfo.Size(), srcFileInfo.Name(), c.ProgressWriter)
writer = io.MultiWriter(canceler, dstFile, progressBar)
writer = io.MultiWriter(canceler, dstFile, c.ProgressWriter(srcFileInfo))
} else {
writer = io.MultiWriter(canceler, dstFile)
}
Expand Down Expand Up @@ -448,8 +447,8 @@ func (c *cancelWriter) Write(b []byte) (int, error) {
return len(b), nil
}

// newProgressBar returns a new progress bar that writes to writer.
func newProgressBar(size int64, desc string, writer io.Writer) *progressbar.ProgressBar {
// NewProgressBar returns a new progress bar that writes to writer.
func NewProgressBar(size int64, desc string, writer io.Writer) *progressbar.ProgressBar {
// this is necessary because progressbar.DefaultBytes doesn't allow
// the caller to specify a writer
return progressbar.NewOptions64(
Expand Down
25 changes: 25 additions & 0 deletions lib/teleterm/api/proto/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ service TerminalService {
rpc LoginPasswordless(stream LoginPasswordlessRequest) returns (stream LoginPasswordlessResponse);
// ClusterLogin logs out a user from cluster
rpc Logout(LogoutRequest) returns (EmptyResponse);
// TransferFile sends a request to download/upload a file
rpc TransferFile(FileTransferRequest) returns (stream FileTransferProgress);
}

// RemoveClusterRequest describes RemoveClusterRequest
Expand Down Expand Up @@ -165,6 +167,29 @@ message LoginPasswordlessRequest {
}
}

message FileTransferRequest {
string cluster_uri = 1;
string login = 2;
string hostname = 3;
// source path of the transferred file
string source = 4;
// destination path of the transferred file
string destination = 5;
// indicates whether the file is uploaded/downloaded
FileTransferDirection direction = 6;
}

// FileTransferDirection describes directions of a file transfer
enum FileTransferDirection {
FILE_TRANSFER_DIRECTION_UNSPECIFIED = 0;
FILE_TRANSFER_DIRECTION_DOWNLOAD = 1;
FILE_TRANSFER_DIRECTION_UPLOAD = 2;
}

message FileTransferProgress {
uint32 percentage = 1;
}

// LoginRequest describes cluster login request
message LoginRequest {
// cluster_uri is the cluster uri
Expand Down
Loading