Topic "Automatically zip folder before SFTP transfer"

Author Message
[View user's profile]

Joined: 2016-06-22
Posts: 1

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"

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

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License