@@ -121,6 +121,25 @@ 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. Defaults to <see langword="true"/>.
127+ /// </summary>
128+ /// <remarks>
129+ /// The "-d" flag is an undocumented flag that ensures that the target is actually a directory. However,
130+ /// some scp implementations (like Cisco) do not support this flag and will fail.
131+ /// You can set this to <see langword="false"/> to work around this.
132+ /// </remarks>
133+ public bool UseDirectoryFlag { get ; set ; } = true ;
134+
135+ private string EnsureIsDirectoryArg
136+ {
137+ get
138+ {
139+ return UseDirectoryFlag ? "-d" : string . Empty ;
140+ }
141+ }
142+
124143 /// <summary>
125144 /// Occurs when downloading file.
126145 /// </summary>
@@ -258,9 +277,9 @@ public void Upload(Stream source, string path)
258277 channel . Closed += ( sender , e ) => input . Dispose ( ) ;
259278 channel . Open ( ) ;
260279
261- // Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
280+ // Pass only the directory part of the path to the server, and optionally use the (hidden) -d option to signal
262281 // that we expect the target to be a directory.
263- if ( ! channel . SendExecRequest ( string . Format ( "scp -t -d {0}" , _remotePathTransformation . Transform ( posixPath . Directory ) ) ) )
282+ if ( ! channel . SendExecRequest ( $ "scp -t { EnsureIsDirectoryArg } { _remotePathTransformation . Transform ( posixPath . Directory ) } " ) )
264283 {
265284 throw SecureExecutionRequestRejectedException ( ) ;
266285 }
@@ -301,9 +320,9 @@ public void Upload(FileInfo fileInfo, string path)
301320 channel . Closed += ( sender , e ) => input . Dispose ( ) ;
302321 channel . Open ( ) ;
303322
304- // Pass only the directory part of the path to the server, and use the (hidden) -d option to signal
323+ // Pass only the directory part of the path to the server, and optionally use the (hidden) -d option to signal
305324 // that we expect the target to be a directory.
306- if ( ! channel . SendExecRequest ( $ "scp -t -d { _remotePathTransformation . Transform ( posixPath . Directory ) } ") )
325+ if ( ! channel . SendExecRequest ( $ "scp -t { EnsureIsDirectoryArg } { _remotePathTransformation . Transform ( posixPath . Directory ) } ") )
307326 {
308327 throw SecureExecutionRequestRejectedException ( ) ;
309328 }
@@ -352,7 +371,7 @@ public void Upload(DirectoryInfo directoryInfo, string path)
352371 // -r copy directories recursively
353372 // -d expect path to be a directory
354373 // -t copy to remote
355- if ( ! channel . SendExecRequest ( $ "scp -r -p -d -t { _remotePathTransformation . Transform ( path ) } ") )
374+ if ( ! channel . SendExecRequest ( $ "scp -r -p { EnsureIsDirectoryArg } -t { _remotePathTransformation . Transform ( path ) } ") )
356375 {
357376 throw SecureExecutionRequestRejectedException ( ) ;
358377 }
0 commit comments