Synchronize batch file for changing file name

Advertisement

fiyapondat
Joined:
Posts:
6
Location:
Washington, DC

Synchronize batch file for changing file name

I'm trying to use a batch file to synchronize folders. The files I need name changes daily and I'm looking for a way to do using a batch. I have the file written up but can't find the command to grab the files. When i use the sync command in WinSCP I can filter to the specific files using *.file type. does anyone know if this can be accomplished in a batch or do I have to user powershell or something else? I know i can set it to grab the entire directory but I want to know if there is a way to say "only grab files with this extension.

Here is what I have so far:

@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\writable\path\to\log\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://unknkown:VFLx98u3g@files.insighthosting.com/ -hostkey=""ssh-rsa 1024 c36bXCOIuJJlXQcAxy3DLz+UYidT6Ylhfjdk4syUk="" -rawsettings CacheDirectories=0 CacheDirectoryChanges=0" ^    
"synchronize local E:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER2016\MSSQL\Backup /production/90872/backup/" ^
 
"exit" 
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
pause
exit /b %WINSCP_RESULT%

Reply with quote

Advertisement

fiyapondat
Joined:
Posts:
6
Location:
Washington, DC

Re: Synchronize batch file for changing file name

Thank you, that's exactly what I was looking for but the code seems to be wrong somewhere. It gave me the error "is not recognized as an internal or external command. so I added the quotes to fix it and now it says the 'the filename, directory name or volume label syntax is incorrect. So I got more specific with the logic. This is where I am right now

"synchronize -filemask=17087dm????1_compressed.bak local E:\blah\blah\blah" "/blah/blah/blah" ^

I've also tried
"synchronize -filemask=17087dm*1_compressed.bak local E:\blah\blah\blah" "/blah/blah/blah"
local and got the same error:

the filename, directory name, or volume label syntax is incorrect. any ideas?

Reply with quote

fiyapondat
Joined:
Posts:
6
Location:
Washington, DC

Re: Synchronize batch file for changing file name

I used the double quotes and got some syntax errors so I removed them and removed the spaces. Now I'm back to the error "the filename, directory name, or volume syntax is incorrect. This is the line I have now.

"synchronize -filemask=17087dm????1_compressed.bak local "E:\ProgramFiles\MicrosoftSQLServer\MSSQL13.MSSQLSERVER2016\MSSQL\Backup" "/production/17087/backup/" ^

Reply with quote

Advertisement

martin
Site Admin
martin avatar

Re: Synchronize batch file for changing file name

That's wrong. Show us your full command-line with my version of the command and a session log file for that.

Reply with quote

fiyapondat
Joined:
Posts:
6
Location:
Washington, DC

Re: Synchronize batch file for changing file name

Noticed that I didn't even have the freaking right path for the log file and that caused the error. So now it opens a session and just sits there, doesn't run the next line. Code below

@echo off

"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\log\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://blah :blah blah@files.blackbaudhosting.com/ -hostkey=""blah blah blah="" -rawsettings CacheDirectories=0 CacheDirectoryChanges=0" ^    
"synchronize -filemask=17087dm*1_compressed.bak local "E:\ProgramFiles\MicrosoftSQLServer\MSSQL13.MSSQLSERVER2016\MSSQL\Backup" "/production/17087/backup/" ^




set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)

pause
exit /b %WINSCP_RESULT%

Reply with quote

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

Re: Synchronize batch file for changing file name

You have spaces after the ^ at the open line. And you do not have spaces at the front of the synchronize line. And you are missing exit command. And you still have the quotes wrong.
Please read the article, I've posted above already:
https://winscp.net/eng/docs/faq_batch_file

@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\log\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://blah :blah blah@files.blackbaudhosting.com/ -hostkey=""blah blah blah="" -rawsettings CacheDirectories=0 CacheDirectoryChanges=0" ^    
    "synchronize -filemask=17087dm*1_compressed.bak local ""E:\ProgramFiles\MicrosoftSQLServer\MSSQL13.MSSQLSERVER2016\MSSQL\Backup"" ""/production/17087/backup/""" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
pause
exit /b %WINSCP_RESULT%

Reply with quote

fiyapondat
Joined:
Posts:
6
Location:
Washington, DC

The reason I removed "exit" is because it reports back that it's not recognized as an internal or external command. I definitely messed up with the spaces, I've been added and removing lines from it throughout testing. The error that I'm working through with everything corrected is:

Too many parameters for command synchronize

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum