Skip to content

Commit

Permalink
[v11] Add file transfer support to Connect (#17209)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzdunek authored Oct 10, 2022
1 parent 5dc1f28 commit 7e300d0
Show file tree
Hide file tree
Showing 11 changed files with 1,531 additions and 469 deletions.
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

0 comments on commit 7e300d0

Please sign in to comment.