@@ -121,6 +121,23 @@ public IRemotePathTransformation RemotePathTransformation
121121 }
122122 }
123123
124+ /// <summary>
125+ /// Gets or sets a value indicating whether the "-d" flag should be passed to the scp process on the server
126+ /// when uploading files.
127+ /// The "-d" flag is an undocumented flag that ensures that the target is actually a directory. However,
128+ /// some scp implementations (like Cisco) do not support this flag and will fail.
129+ /// You can set this to <see langword="false"/> to work around this.
130+ /// </summary>
131+ public bool UseDirectoryFlag { get ; set ; } = true ;
132+
133+ private string EnsureIsDirectoryArg
134+ {
135+ get
136+ {
137+ return UseDirectoryFlag ? "-d" : string . Empty ;
138+ }
139+ }
140+
124141 /// <summary>
125142 /// Occurs when downloading file.
126143 /// </summary>
@@ -258,9 +275,9 @@ public void Upload(Stream source, string path)
258275 channel . Closed += ( sender , e ) => input . Dispose ( ) ;
259276 channel . Open ( ) ;
260277
261- // Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
278+ // Pass only the directory part of the path to the server, and optionally use the (hidden) -d option to signal
262279 // that we expect the target to be a directory.
263- if ( ! channel . SendExecRequest ( string . Format ( "scp -t -d {0}" , _remotePathTransformation . Transform ( posixPath . Directory ) ) ) )
280+ if ( ! channel . SendExecRequest ( $ "scp -t { EnsureIsDirectoryArg } { _remotePathTransformation . Transform ( posixPath . Directory ) } " ) )
264281 {
265282 throw SecureExecutionRequestRejectedException ( ) ;
266283 }
@@ -301,9 +318,9 @@ public void Upload(FileInfo fileInfo, string path)
301318 channel . Closed += ( sender , e ) => input . Dispose ( ) ;
302319 channel . Open ( ) ;
303320
304- // Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
321+ // Pass only the directory part of the path to the server, and optionally use the (hidden) -d option to signal
305322 // that we expect the target to be a directory.
306- if ( ! channel . SendExecRequest ( $ "scp -t -d { _remotePathTransformation . Transform ( posixPath . Directory ) } ") )
323+ if ( ! channel . SendExecRequest ( $ "scp -t { EnsureIsDirectoryArg } { _remotePathTransformation . Transform ( posixPath . Directory ) } ") )
307324 {
308325 throw SecureExecutionRequestRejectedException ( ) ;
309326 }
@@ -352,7 +369,7 @@ public void Upload(DirectoryInfo directoryInfo, string path)
352369 // -r copy directories recursively
353370 // -d expect path to be a directory
354371 // -t copy to remote
355- if ( ! channel . SendExecRequest ( $ "scp -r -p -d -t { _remotePathTransformation . Transform ( path ) } ") )
372+ if ( ! channel . SendExecRequest ( $ "scp -r -p { EnsureIsDirectoryArg } -t { _remotePathTransformation . Transform ( path ) } ") )
356373 {
357374 throw SecureExecutionRequestRejectedException ( ) ;
358375 }
0 commit comments