@@ -124,6 +124,23 @@ func WriteRemoteFile(ctx context.Context, conn *proxy.Conn, config *FileConfig,
124
124
return nil
125
125
}
126
126
127
+ // RemoveRemoteFile is a helper function for removing a file on a remote host
128
+ // using a proxy.Conn. If the conn is defined for >1 targets this will return an error.
129
+ func RemoveRemoteFile (ctx context.Context , conn * proxy.Conn , path string ) error {
130
+ if len (conn .Targets ) != 1 {
131
+ return errors .New ("RemoveRemoteFile only supports single targets" )
132
+ }
133
+
134
+ c := pb .NewLocalFileClient (conn )
135
+ _ , err := c .Rm (ctx , & pb.RmRequest {
136
+ Filename : path ,
137
+ })
138
+ if err != nil {
139
+ return fmt .Errorf ("remove problem - %v" , err )
140
+ }
141
+ return nil
142
+ }
143
+
127
144
// CopyRemoteFile is a helper function for copying a file on a remote host
128
145
// using a proxy.Conn. If the conn is defined for >1 targets this will return an error.
129
146
func CopyRemoteFile (ctx context.Context , conn * proxy.Conn , source string , destination * FileConfig ) error {
@@ -164,7 +181,7 @@ func CopyRemoteFile(ctx context.Context, conn *proxy.Conn, source string, destin
164
181
}
165
182
_ , err := c .Copy (ctx , req )
166
183
if err != nil {
167
- return fmt .Errorf ("Copy problem for %s -> %s: %v" , source , destination .Filename , err )
184
+ return fmt .Errorf ("copy problem for %s -> %s: %v" , source , destination .Filename , err )
168
185
}
169
186
return nil
170
187
}
0 commit comments