Differences

This shows you the differences between the selected revisions of the page.

library_example_moves_files_keeping_directory_structure 2018-02-20 library_example_moves_files_keeping_directory_structure 2023-11-15 (current)
Line 8: Line 8:
==== C# ==== ==== C# ====
-Use the ''[[https://msdn.microsoft.com/en-us/library/dd383689.aspx|DirectoryInfo.EnumerateFileSystemInfos]]'' method to walk the source local tree.+Use the ''[[dotnet>system.io.directoryinfo.enumeratefilesysteminfos|DirectoryInfo.EnumerateFileSystemInfos]]'' method to walk the source local tree.
<code csharp> <code csharp>
Line 29: Line 29:
                UserName = "user",                 UserName = "user",
                Password = "mypassword",                 Password = "mypassword",
-                SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx..."+                SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
            };             };
Line 48: Line 48:
                {                 {
                    string remoteFilePath =                     string remoteFilePath =
-                        session.TranslateLocalPathToRemote(+                        RemotePath.TranslateLocalPathToRemote(
                            fileInfo.FullName, localPath, remotePath);                             fileInfo.FullName, localPath, remotePath);
Line 80: Line 80:
==== [[upload_powershell]] PowerShell ==== ==== [[upload_powershell]] PowerShell ====
 +
 +You can install this script as an [[extension|WinSCP extension]] by using this page URL in the //[[ui_pref_commands#extensions|Add Extension]]// command.
<code powershell - UploadDeleteKeepStructure.ps1> <code powershell - UploadDeleteKeepStructure.ps1>
# @name        Upload and Delete Files # @name        Upload and Delete Files
-# @command      powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%" -sessionUrl "!S" -remotePath "!/" -sessionLogPath "%SessionLogPath%" -pause !& +# @command      powershell.exe -ExecutionPolicy Bypass -File "%EXTENSION_PATH%"
-# @description  Moves selected local files to a remote directory, but keeps local directory structure+#                  -sessionUrl "!E" -remotePath "!/" -sessionLogPath "%SessionLogPath%"
 +#                  -pause !& 
 +# @description  Moves selected local files to a remote directory,
 +#                  but keeps local directory structure
# @flag        ApplyToDirectories # @flag        ApplyToDirectories
-# @version      3+# @version      5
# @homepage    ~~SELF~~ # @homepage    ~~SELF~~
-# @require      WinSCP 5.8.4+# @require      WinSCP 5.16
# @option      SessionLogPath -config sessionlogfile # @option      SessionLogPath -config sessionlogfile
# @optionspage  ~~SELF~~#options # @optionspage  ~~SELF~~#options
Line 95: Line 100:
    # Use Generate Session URL function to obtain a value for -sessionUrl parameter.     # Use Generate Session URL function to obtain a value for -sessionUrl parameter.
    [Parameter(Mandatory = $True)]     [Parameter(Mandatory = $True)]
-    $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xx-xx-xx@example.com/",+    $sessionUrl = "sftp://user:mypassword;fingerprint=ssh-rsa-xxxxxxxxxxx...@example.com/",
    [Parameter(Mandatory = $True)]     [Parameter(Mandatory = $True)]
    $remotePath,     $remotePath,
Line 143: Line 148:
            {             {
                $remoteFilePath =                 $remoteFilePath =
-                    $session.TranslateLocalPathToRemote(+                    [WinSCP.RemotePath]::TranslateLocalPathToRemote(
                        $localFilePath, $parentLocalPath, $remotePath)                         $localFilePath, $parentLocalPath, $remotePath)
Line 189: Line 194:
</code> </code>
-== [[options]] Options ==+=== [[options]] Options ==
 + 
 +In the //Session log file//, you can specify a path to a [[logging|session log file]].
-In the //Session log file// you can specify a path to a [[logging|session log file]].+In the //Keyboard shortcut//, you can specify a [[custom_key_shortcuts|keyboard shortcut]] for the extension.
-===== Download =====+===== [[download]] Download =====
-For a download, you can use the code from the [[library_example_recursive_download_custom_error_handling|Recursively download directory tree with custom error handling]] example.+For a download, you can use the code from the [[library_example_recursive_download_custom_error_handling#tree_download|Explicit implementation of a file tree download section of Recursively download directory tree with custom error handling]] example.
Just pass a ''true'' to the optional ''[[library_session_getfiles#remove|remove]]'' parameter of the ''[[library_session_getfiles|Session.GetFiles]]''. Just pass a ''true'' to the optional ''[[library_session_getfiles#remove|remove]]'' parameter of the ''[[library_session_getfiles|Session.GetFiles]]''.
Line 202: Line 209:
<code csharp> <code csharp>
-string remoteFilePath = RemotePath.EscapeFileMask(fileInfo.FullName); +session.GetFiles(remoteFilePath, localFilePath, true).Check();
-session.GetFiles(remoteFilePath, localFilePath, true);+
</code> </code>
Line 209: Line 215:
<code powershell> <code powershell>
-$remoteFilePath = [WinSCP.RemotePath]::EscapeFileMask($fileInfo.FullName) +$session.GetFiles($remoteFilePath, $localFilePath, $True).Check()
-$session.GetFiles($remoteFilePath, $localFilePath, $True)+
</code> </code>

Last modified: by martin