Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

No. That's not the code from the article, it should be like:
set TIMESTAMP_FORMAT=yyyy-mm-dd
 
for /F "tokens=* USEBACKQ" %%F in (
    `winscp.com /command "echo %%TIMESTAMP#%TIMESTAMP_FORMAT%%%" "exit"`
) do set TIMESTAMP=%%F
 
zip -r "backup-%TIMESTAMP%.zip" C:\Backups

I do not know about the zip commandline syntax, that depends on what implementation of ZIP you have. And that's not a WinSCP question anyway.
Shay_

@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://stuff@stuff/ -hostkey="""" -rawsettings FSProtocol=2 ProxyPort=0" ^
    "cd /17539" ^
    "lcd C:\Backups" ^
    "get folder" ^
    "get folder" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
    "zip -r "backup.zip" "!/"" ^
    "set TIMESTAMP_FORMAT=yyyy-mm-dd
winscp.com /command "echo %%TIMESTAMP#%TIMESTAMP_FORMAT%%%" "exit""
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

Did I do this correctly?
Shay_

An example if I were to use the zip command. You said execute zip once the download finishes right? So would it be something like this?
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://stuff@stuff/ -hostkey="""" -rawsettings FSProtocol=2 ProxyPort=0" ^
    "cd /17539" ^
    "lcd C:\Backups" ^
    "get folder" ^
    "get folder" ^
    "zip -r "backup-`date +%Y%m%d%H%M`.zip" "backup/"" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%


I saw the command in another thread, but I'm not sure if it's the exact one I need to use. Right now I just want to download two folders and zip them into the directory with a timestamp.
martin

Example of what? Using the mkdir?
mkdir C:\Backups
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
...
Shay_

Sorry, I'm really new to all this. Could I get an example with my batch code?
If I do zip files, I'm hoping it'll create a zip each time with a timestamp so they're easy to track.
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp://stuff@stuff/ -hostkey="""" -rawsettings FSProtocol=2 ProxyPort=0" ^
    "cd /17539" ^
    "lcd C:\Backups" ^
    "get folder" ^
    "get folder" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%
martin

Re: Creating a folder to download into

Create the folder in the batch file using mkdir command. And then execute WinSCP from the same batch file for the download.

Similarly, if you want to ZIP the downloaded files, execute the "zip" after WinSCP finishes with the download.
Shay_

Creating a folder to download into

As title says, is it possible to have the batch file create a folder and download files into it so I can have multiple backups?
Also is it possible to download into a compressed zip file?