Copy files from one remote directory to another remote directory on the same server

Advertisement

KishorP
Joined:
Posts:
1

Copy files from one remote directory to another remote directory on the same server

I want to copy and move files from one remote directory (
/Test
) to another remote directory (
/KMPTest
) on the same remote server.
I tried to use session.DuplicateFile but it only let me copy one file only.
My directories on the remote:[/code]
Root --> /
Source Directory -->  /Test
integrationShareDir  -->  /KMPTest
I tried
PutFiles
as:
transferResult = session.PutFiles(sourceDirectory + "/*.txt", integrationShareDir+ "/", false, transferOptions);
However, log says:
pwd
< 2020-06-17 11:04:13.853 Script: /
> 2020-06-17 11:04:16.815 Script: put -nopermissions -preservetime -transfer="binary" -filemask="|*/" -- "/Test/*.txt" "/KMPTest/"
< 2020-06-17 11:04:16.866 Script: No file matching '/Test/*.txt' found. (System Error. Code: 3.
Note that
MoveFile
works fine, with the same specification:
session.MoveFile(sourceDirectory + "/*.txt", integrationShareDir + "/");
.
Both of the above command works if I specify a local directory
C:\Temp
for the
integrationShareDir
.

Also, GetFiles copies files to my local executable directory, ignoring /KMPTest on the remote.

Where may be I am going wrong to make
PutFile
Work?
Thank you,
Kishor

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: Copy files from one remote directory to another remote directory on the same server

If you need to make a copy of whole folder, you will need to call Session.DuplicateFile for each file individually.

Though if you use SFTP/SCP protocol, note that the method internally calls shell command cp. So you might want to call cp -r ... using Session.ExecuteCommand instead.
https://winscp.net/eng/docs/library_session_executecommand

Reply with quote

Advertisement

You can post new topics in this forum