DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel
Explore NY Stream

— Kiaasa Dhanori Pune

Take backup using winrar & ftp the data using text input

A WinRAR backup batch script lets you compress folders into a password-protected .rar archive and push it to a remote server automatically, without touching a GUI. The classic approach pairs the WinRAR command line with the built-in Windows ftp client driven by a text input file, then schedules the whole thing with Task Scheduler. This guide shows the working script, fixes the security holes in the legacy pattern, and gives you a safer modern equivalent.

The problem this WinRAR backup batch script solves

You have a folder of important data, for example a Softwares directory on drive E:, and you want a nightly job that does three things with zero clicks: compress it, lock it with a password, and copy the archive offsite to a backup server. Doing this by hand is slow and easy to forget, which is exactly how backups end up missing the day you need them.

The solution is a single batch file (.bat) that calls WinRAR from the command line to build the archive, then calls the Windows ftp command with a script input file so the transfer runs unattended. Both tools accept all their instructions up front, so nothing pauses to wait for a human.

What you need before you start

  • WinRAR installed (the console tool is WinRAR.exe, and there is also a pure CLI build called Rar.exe in the same folder).
  • A destination folder for the archives, e.g. C:\WBackups\.
  • An FTP/SFTP server you control, with a real username and password.
  • Permission to write a batch file and create a Scheduled Task.

Step-by-step: build the WinRAR backup batch script

Work through these steps in order. Each command is shown exactly as it goes into the .bat file.

  1. Create the archive with a password and recursion. The a command adds files to an archive, -r recurses into subfolders, and -hp encrypts both the file data and the file names with your password:

    "C:\Program Files\WinRAR\WinRAR.exe" a -hpYourStrongPassword -r C:\WBackups\softwares.rar E:\W2\Softwares

  2. Move to the backup folder so relative paths and the FTP put resolve cleanly:

    cd /d C:\WBackups\

    The /d switch lets cd change the drive letter too, which plain cd will not do.

  3. Confirm the file exists before the upload, so the log shows what was built:

    dir softwares.rar

  4. Run the unattended FTP transfer using a script file with -s:. The last argument is the server host or IP:

    ftp -s:C:\Scripts\ftp_upload.txt 10.170.4.99

  5. Write a timestamped completion line to the log so you can audit runs:

    echo [%DATE%] [%TIME%] Done uploading softwares.rar.>> C:\WBackups\backup.log

The FTP input file explained line by line

The Windows ftp client reads the -s: file one line per command, in order, as if you typed them at the ftp> prompt. A correct, working ftp_upload.txt looks like this:

Line in fileWhat it does
your_usernameThe FTP login name (first line = username).
your_passwordThe password (second line, sent in clear text — see the security note).
binarySwitches to binary mode so the .rar is not corrupted by text translation.
cd /backupsChanges to the remote target directory.
put softwares.rarUploads the archive from the current local folder.
quitCloses the session cleanly.

Important correction to the legacy pattern: the old script used the literal command bi to set binary mode. The Windows ftp client does not recognise bi — the full keyword is binary (its alias is bin). Using bi silently leaves you in ASCII mode, which is the most common cause of archives that download but refuse to extract.

Why the anonymous-FTP version is a mistake — and how to fix it

A widely copied version of this WinRAR backup batch script logs in as anonymous and embeds the password directly in the .bat file. Both choices are problems you should fix before trusting this in production:

  • Anonymous FTP is read-mostly and insecure. Most anonymous servers reject uploads, and those that accept them let anyone retrieve your backup. Always authenticate with a real, least-privilege account.
  • Plaintext credentials. Both the batch file and the FTP script store the password in clear text, and FTP itself transmits it unencrypted over the wire. Anyone with read access to the file or the network segment can capture it.
  • Encrypt the archive, not just the transfer. Use WinRAR's -hp (header + data encryption) rather than -p alone, so filenames inside the archive are hidden too.

Treat the legacy plain-FTP design as a teaching example. For anything real, move to SFTP/FTPS, covered in the modern equivalent below.

Useful WinRAR command-line switches

SwitchPurpose
aAdd files to an archive (the core command).
-rRecurse into subdirectories.
-hpPASSWORDEncrypt data and file names with PASSWORD (no space after -hp).
-m5Maximum compression (use -m1 for fastest).
-ep1Exclude the base folder path so the archive is not deeply nested.
-agAppend the date/time to the archive name, e.g. for daily snapshots.
-rr5%Add a 5% recovery record to survive minor corruption.

A robust archive line that timestamps each backup looks like this:

"C:\Program Files\WinRAR\WinRAR.exe" a -hpYourStrongPassword -r -m5 -rr5% -ag_YYYYMMDD C:\WBackups\softwares.rar E:\W2\Softwares

Scheduling the WinRAR backup batch script to run nightly

Save the batch file as C:\Scripts\winrar_backup.bat, then automate it with Task Scheduler:

  1. Open Task Scheduler (taskschd.msc) and choose Create Basic Task.
  2. Name it, e.g. Nightly Software Backup, and set a Daily trigger at a quiet hour like 02:00.
  3. For the action, choose Start a program and point it at C:\Scripts\winrar_backup.bat.
  4. In the task properties, tick Run whether user is logged on or not and Run with highest privileges so it works headless.
  5. Prefer the command line? Register it in one shot:

    schtasks /Create /SC DAILY /ST 02:00 /TN "Nightly Software Backup" /TR "C:\Scripts\winrar_backup.bat" /RL HIGHEST

Common pitfalls and how to avoid them

  • Spaces in the WinRAR path. Always quote "C:\Program Files\WinRAR\WinRAR.exe"; an unquoted path breaks at the space.
  • No space after -hp or -p. The password must be glued to the switch: -hpSecret, not -hp Secret.
  • ASCII vs binary FTP. Forgetting binary (or writing the invalid bi) corrupts the .rar. Always set binary before put.
  • Wrong working directory. If you do not cd /d into the archive folder, put softwares.rar cannot find the file. Use a full path in put if you prefer not to cd.
  • Passive mode and firewalls. The Windows ftp client uses active mode and often fails behind NAT. Switch tools or use a client that supports passive (PASV) mode.
  • WinRAR exit codes ignored. WinRAR returns 0 on success and non-zero on error. Check %ERRORLEVEL% after the archive step and skip the upload if it failed.
  • Silent overwrites. Without -ag or a date in the name, each run overwrites yesterday's archive, leaving you with exactly one restore point.

A safer modern equivalent: PowerShell + SFTP

The batch-plus-plain-FTP approach still works, but plain FTP is effectively obsolete because it sends credentials and data unencrypted. The modern equivalent keeps the same idea — compress, then upload — while encrypting the transfer. Use WinRAR (or the built-in Compress-Archive for unencrypted zips) to build the archive, then upload over SFTP with WinSCP's scripting engine or the Posh-SSH PowerShell module.

A WinSCP scripted upload, called from your batch or PowerShell job, replaces the entire FTP text file:

winscp.com /command "open sftp://user:pass@backup.example.com/ -hostkey=*" "put C:\WBackups\softwares.rar /backups/" "exit"

For credentials, store the password in Windows Credential Manager or a protected variable rather than in the script body, and prefer SSH key authentication so no password appears at all. This gives you the same hands-off nightly backup with the encryption that plain FTP lacks.

Verification: confirm the backup actually works

A backup you have never restored is only a hope. Verify every link in the chain:

  1. Test the archive integrity right after creation: "C:\Program Files\WinRAR\WinRAR.exe" t -hpYourStrongPassword C:\WBackups\softwares.rar — it reports All OK when the archive is valid.
  2. Check the upload landed by listing the remote folder (add a dir line to the FTP script, or list it via SFTP) and comparing the file size to the local copy.
  3. Read the log. Open C:\WBackups\backup.log and confirm a fresh timestamped Done line for the latest run.
  4. Do a real restore test periodically: download the archive to a clean machine and extract it with the password to confirm the data is intact and openable.
  5. Confirm the schedule fired in Task Scheduler's History tab, where the Last Run Result should read 0x0.

Key Takeaways

  • Compress with WinRAR.exe a -hpPASSWORD -r to get a recursive, fully encrypted archive, and quote the program path.
  • Drive the Windows ftp client with a -s: script file; use binary (never the invalid bi) before put.
  • Avoid anonymous FTP and plaintext passwords — authenticate with a real least-privilege account and prefer SFTP/FTPS.
  • Schedule the .bat with Task Scheduler (schtasks), running headless with highest privileges, and timestamp each archive so you keep multiple restore points.
  • Always verify: test archive integrity with t, confirm the remote file size, and run a periodic real restore.

Frequently Asked Questions

How do I password-protect a RAR file from the command line?

Use the -hp switch with the password attached and no space: WinRAR.exe a -hpMyPass -r archive.rar C:\Data. The -hp form encrypts both the file contents and the file names, while plain -p leaves the names visible.

Why does my uploaded RAR file fail to extract?

The most common cause is an ASCII-mode FTP transfer, which alters byte sequences in binary files. Add a binary line to your FTP script before the put command, and never use the unsupported bi abbreviation, which leaves you in the wrong mode.

Is the Windows ftp command secure for backups?

No. The built-in ftp client uses plain FTP, which transmits your username, password, and data unencrypted. For real backups switch to SFTP or FTPS using a tool such as WinSCP or the Posh-SSH PowerShell module, and store credentials in Windows Credential Manager rather than in the script.

How can I keep multiple daily backups instead of overwriting one?

Add the -ag switch (or embed %DATE% in the archive name) so each run produces a uniquely dated file like softwares_2026-06-28.rar. Then schedule a cleanup that deletes archives older than your retention window.

For more practical Windows sysadmin and automation walkthroughs, subscribe on YouTube @explorenystream.