Post a reply

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)


Topic review


Fixed. Needed to use 7zip and perform the compression before the transfer.

"C:\Program Files\7-Zip\7z.exe" a -r %BackupFile% D:\Report\Today

Automatically zip folder before SFTP transfer


I am having difficulty getting my WinSCP script to compress a folder containing large CSVs and unfortunately have no found an answer in the forum posts.

I am using a wrapper script to create a Windows batch file which runs as a scheduled task.

I am unsure whether I need to create a WinSCP custom zip command or whether I am even on the right track trying to compress the folder within my script. Any advice would be appreciated!

Here is my current code:


REM Local directory where CSV files are found
SET LCD=D:\Report\Today

REM The local directory where script files are kept

REM change to SFTP folder

REM Delete batch file config
DEL "%WORKDIR%\SFTP_today.txt"

REM Create text file with transfer parameters
REM Connect
ECHO option batch on > "%WORKDIR%\SFTP_today.txt"
ECHO option confirm off >> "%WORKDIR%\SFTP_today.txt"
ECHO open %SFTPURL% -hostkey="ssh-rsa 123abc">> "%WORKDIR%\SFTP_today.txt"

REM change to remote folder
ECHO cd Today >> "%WORKDIR%\SFTP_today.txt"
REM change to local folder
ECHO lcd %LCD% >> "%WORKDIR%\SFTP_today.txt"

REM create zip folder zipFileName | folderName
ECHO zip -r D:\Reports\ D:\Reports\Today >> "%WORKDIR%\SFTP_zip.txt"

REM transfer zip file
ECHO put *.zip>> "%WORKDIR%\SFTP_today.txt"

REM exit
ECHO bye >> "%WORKDIR%\SFTP_today.txt"

REM run script
"%WORKDIR%\" /script="%WORKDIR%\SFTP_today.txt"