Synchronize remote with local and exclude subdirectories

Advertisement

JanneFiH
Guest

Synchronize remote with local and exclude subdirectories

I've this directory locally that I'd like to synchronize with a remote server. (I want my remote server to look like the local directory)
/DIR
 -> /A
 -> /B
 -> /C
I would like to exclude subdirectories within A, B and C from being synchronized.
I also have some files in /DIR that I also would like to be excluded from being synchronized. Just files in /A/, /B/ and /C/. I don't want to accidentally delete files or folders on either local or remote.

I don't get the .bat-file to start. Can anyone please check what I'm doing wrong? It doesn't post to the log file.
    "open ftp://USER:PASSWORD@IP:PORT/ -passive=0" ^
    "cd /DIR/A/" ^
    "lcd C:\A\ ^
    "synchronize remote -delete -nopermissions -transfer=binary -filemask="|*/" * ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%
Thanks in advance!

Reply with quote

Advertisement

Guest

Re: Synchronize remote with local and exclude subdirectories

I'm sorry. I censored myself when writing the topic.
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="F:\skrivbord\log\WinUPP.log" /ini=nul ^
  /command ^
    "open ftp://USER:PASSWORD@IP:PORT/ -passive=0" ^ 
    "cd /DIR/A/" ^ 
    "lcd C:\A\ ^ 
    "synchronize remote -delete -nopermissions -transfer=binary -filemask="|*/" * ^ 
    "exit" 
 
set WINSCP_RESULT=%ERRORLEVEL% 
if %WINSCP_RESULT% equ 0 ( 
  echo Success 
) else ( 
  echo Error 
) 
 
exit /b %WINSCP_RESULT%

Reply with quote

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

Re: Synchronize remote with local and exclude subdirectories

You are missing some quotes.

Here:
    "lcd C:\A\" ^
And here:
    "synchronize remote -delete -nopermissions -transfer=binary -filemask=""|*/"" * ^
See https://winscp.net/eng/docs/commandline#syntax

Also make sure that the ^'s are the very last characters on their respective lines (there cannot be any space after them).
See Why are some WinSCP scripting commands specified in a batch file not executed/failing?
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="F:\skrivbord\log\WinUPP.log" /ini=nul ^
  /command ^
    "open ftp://USER:PASSWORD@IP:PORT/ -passive=0" ^
    "cd /DIR/A/" ^
    "lcd C:\A\" ^
    "synchronize remote -delete -nopermissions -transfer=binary -filemask=""|*/"" * ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL% 
if %WINSCP_RESULT% equ 0 ( 
  echo Success 
) else ( 
  echo Error 
) 
 
exit /b %WINSCP_RESULT%

Reply with quote

JanneFiH
Guest

Re: Synchronize remote with local and exclude subdirectories

Thank you for your corrections, Martin!

Now I at least receive an error log. It's written in my native language.
. 2017-10-27 06:09:47.106 Asking user:
. 2017-10-27 06:09:47.106 Fel uppstod när listning av katalog '*'. ("Fel vid hämtning av fillista för ""*\*.*"".","Systemfel. Kod: 123.","Felaktig syntax för filnamn, katalognamn eller volymetikett")
< 2017-10-27 06:09:47.106 Script: Fel uppstod när listning av katalog '*'.
< 2017-10-27 06:09:47.106 Script: Fel vid hämtning av fillista för "*\*.*".
 
< 2017-10-27 06:09:47.106 Systemfel. Kod: 123.
 
< 2017-10-27 06:09:47.106 Felaktig syntax för filnamn, katalognamn eller volymetikett
< 2017-10-27 06:09:47.107 Script: Fel uppstod när listning av katalog '*'.
< 2017-10-27 06:09:47.107 Fel vid hämtning av fillista för "*\*.*".
 
< 2017-10-27 06:09:47.107 Systemfel. Kod: 123.
 
< 2017-10-27 06:09:47.107 Felaktig syntax för filnamn, katalognamn eller volymetikett
. 2017-10-27 06:09:47.107 Script: Failed
. 2017-10-27 06:09:47.107 Script: Exit code: 1
. 2017-10-27 06:09:47.107 Kopplar ifrån server
Error code 123. It isn't able to fetch file list for "*\*.*"
Please tell me if you would like further translation to be able to see the problem.

Reply with quote

Advertisement

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

Re: Synchronize remote with local and exclude subdirectories

OK, there's one more missing quote, and the * should not be there:
    "synchronize remote -delete -nopermissions -transfer=binary -filemask=""|*/""" ^

Reply with quote

JanneFiH
Guest

Re: Synchronize remote with local and exclude subdirectories

Oh my, Mr Hawkeye himself to notice that! It work's really great now! As always, huge thanks for your help, Martin!

Reply with quote

Advertisement

You can post new topics in this forum