Batch file to zip and upload thru ftp - batch-file

im setting a backup for my pc, can someone help me set a batch file that zip the users folder rename it to date and upload it thru ftp to a server.
Tried some example online with 7zip but the dont seem to work.
thanks
Found this to zip and rename
#ECHO OFF
Title testizarc.bat
REM updated 10/22/2014
REM Replace space in hour with zero if it's less than 10
SET hr=%time:~0,2%
IF %hr% lss 10 SET hr=0%hr:~1,1%
REM This sets the date like this: mm-dd-yr-hrminsecs1/100secs
Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%- %hr%%time:~3,2%%time:~6,2%%time:~9,2%
REM Use IZArc to Zip files in folder c:\testzip and place the zip archive
REM in C:\testmove
ECHO.
ECHO Zipping all files in C:\testzip and moving archive to c:\testmove
ECHO.
izarcc -a -cx "C:\testmove\xxxx_%TODAY%.zip" "C:\testzip\*.*"
ECHO.
ECHO Delete the files in orginal folder
DEL "C:\testzip\*.*"
PAUSE
:end
EXIT /B 0

Related

Batch file to upload files into SharePoint(by giving login details)

I am looking for a batch file which enables me to upload selected files(file names have got spaces in between) into the destination folder on SharePoint which is protected by password.
When I run this batch file, file names which I specified need to erase its older versions and move into that place. Also the files which are not matching should exist in the destination folder.
I got below code from :Copy specific files into subfolder in batch
#ECHO OFF
ECHO Start Copy
set "SOURCE_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in"
set "DEST_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in\Files to Import"
set "FILENAMES_TO_COPY=SN_Router_1.ipt SN_Router_2.ipt SN_Router_3.ipt"
pushd "%SOURCE_DIR%"
for %%F IN (%FILENAMES_TO_COPY%) do (
echo file "%%F"
xcopy /Y "%%F" "%DEST_DIR%\"
)
popd
ECHO. done
pause
I need to add username/password somewhere in this code and if possible the code should accept file names with spaces in it.
Thank you

Batch file for moving files to folders based on filenames

I use Dropbox to automatically upload all the photos/videos I take from my phone to a folder "My Dropbox\Camera Uploads". So this is full of files like:
2015-06-09 10.11.19.jpg
2015-09-11 09.28.46.mp4
I'd now like a batch file to move these to the correct folder (creating it if necessary) "..\Photos\Family\YYYY-MM" where YYYY-MM is the year and month of the photo (i.e. the first seven characters of the filename).
(It has to be a relative rather than absolute path as this Dropbox folder is shared across machines with XP, Vista and Windows 7 OSs, so the first part of the path is different on each.)
I've found similar batch files and tried to tweak them, but just can't get it to work. Many thanks for your help.
You can use this script (put it in a file with extension .bat) and start it:
#echo off
setlocal enabledelayedexpansion
rem For each file in your folder
for %%a in (*.*) do (
echo filename=%%a
rem check if the it is not our script
if "%%a" NEQ "%0" (
set foldername=%%a
set foldername=..\Photos\Family\!foldername:~0,7!
echo foldername=!foldername!
rem check if forlder exists, if not it is created
if not exist "!foldername!" mkdir "!foldername!"
rem Move (or change to copy) the file to directory
move "%%a" "!foldername!\"
)
)

windows batch script to unzip a file

I am trying to create a batch file that gets a zipped folder for that particular date (v_date) from the sftp site and then unzip them. The zip file contains five files that are text documents. I have written batch scripts that successfully get the zip file from the remote site and save a copy of it on the local drive. I need to incorporate the unzip part in to my script.
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
echo option batch continue>FTP_File_Get.txt
echo option confirm off>>FTP_File_Get.txt
echo open Target>>FTP_File_Get.txt
echo lcd "M:\Development\Data History\File" >> FTP_File_Get.txt
echo cd /Export/File >> FTP_File_Get.txt
echo get /Export/File/Filename_%v_date%.zip "M:\Development\DataHistory\Filename_%v_date%.zip">>FTP_File_Get.txt
echo exit>>FTP_File_Get.txt
M:\temp\apps\WinSCP\winscp.com/script="M:\Development\SFTPBatchFiles\FTP_File_Get.txt"
del FTP_File_Get.txt
This is my code to UNZIP:
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
cd "M:\Development\Data History\"
::SET v_file="M:\Development\Data History\Filename_%v_date%.zip"
::unzip -o %v_file%
"C:\Program Files\7-Zip\7z.exe" e "Filename_%v_date%.zip"
I need to move the extracted files (6 Files) into their respective folders, Any help is greatly appreciated
To unzip the files you can use this command line:
"C:\Program Files\7-Zip\7z.exe" e "filename.zip"
#echo off
set "source=%userprofile%\Desktop\basanta\Automation\a"
set "target=%userprofile%\Desktop\basanta\Automation\b"
FOR %%A IN ("%source%\*.gz") DO (
"%programfiles%\7-zip\7z.exe" x "%%~A" -o"%target%\%%~pA"
del "%%~A" /Y
)
Use the above code by saving it to .bat file extension
Remember %userprofile% is for the directory, %programfiles% for the program files set as a variable in windows
hope that helps

Compress/Zip a file using batch file

I need to Compress/Zip an xls file which is generated by my macro.
I have IZarc installed on my machine.
Can somebody please suggest the batch code to zip an xlx file?
This is copy-pasted from this link.
#ECHO OFF
REM Replace space in hour with zero if it's less than 10
SET hr=%time:~0,2%
IF %hr% lss 10 SET hr=0%hr:~1,1%
REM This sets the date like this: mm-dd-yr-hrminsecs1/100secs
Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%-%hr%%time:~3,2%%time:~6,2%%time:~9,2%
REM Use IZArc to Zip files in folder c:\testzip and place the zip archive in C:\testmove
ECHO.
ECHO Zipping all files in C:\testzip and moving archive to c:\testmove
ECHO.
izarcc -a -cx "C:\testmove\xxxx_%TODAY%.zip" "C:\testzip\*.*"
ECHO.
ECHO Delete the files in orginal folder
DEL "C:\testzip\*.*"
PAUSE
For completeness, this script looks good without any cuts.
this utility might be something for you
https://mega.nz/#!4VZnFb6T!nqv0JTqJYLff7e44WQS6-VvhAU-Cs7WBnHZXFd9FRWc
inside there will be 2 .exe files. one for zipping and one for un-zipping. there will also be an .txt file tells you how to use it
virus-total scan
https://www.virustotal.com/da/file/5a38d605e943a1f5ce185e19eb9bda0969d370e7aad9a03575fab7852ed48157/analysis/1488190750/
EXAMPLE OF USAGE:
Zip Files
#echo off
title Zip files in folder
zip.exe zippedxlxfiles path/to/xlxfiles/*.*
pause
Zip a single file
#echo off
title Zip files in folder
zip.exe zippedxlxfiles path/to/xlxfiles/filename.xlx
pause
Note this will zip all the files in the folder you choose
Un-zip Files
#echo off
title Zip files in folder
unzip.exe zippedxlxfiles
pause
Note that this will unzip the files in the same directory as the exe itself

Using 7zip to archive file by year

I have a batch script that runs 7zip and allows me to zip all the files in one folder. I only want to zip files that have a Date Modified of 2010 or another date of my choosing. I want to delete the files after I get them archived into a zip folder. This is my logic.
Find files that are from 2012 and archive those files into a folder called 2012. Zip the folder and delete the files. 0
This is what I have so far.
#ECHO OFF
REM This sets name of the zip file
Set choice=
set /p choice=What is the year of the files?
PAUSE
REM This sets the path of the file
Set path=
set /p path=What is the path of the files on C:\'path'\?
REM Use 7Zip to Zip files in folder c:\path and place the zip archive in C:\path
ECHO.
ECHO Zipping all files in C:\%path% and moving archive to c:\%path%
ECHO.
PAUSE
C:\7z a -tzip "C:\%path%\%choice%.zip" "C:\%path%\*.*" -mx5
ECHO.
PAUSE
ECHO Would you like to Delete the files in orginal folder?
DEL "C:\%path%\*.*"
PAUSE
ECHO File is now zipped
Seems pretty straight forward. By the way, I'm not familiar with 7zip's command-line switches. I'm taking it for granted that you already have the syntax of 7z.exe the way it needs to be.
#echo off
set 7z=C:\7z.exe
if not exist %7z% set /p 7z="Path to 7-zip executable? "
set /p year="What year do you wish to archive? "
set /p dir="What is the path of the files you wish to archive? "
mkdir "%year%"
rem output of dir is date time am/pm size filename
rem filename = 5th + additional tokens
for /f "tokens=5*" %%I in ('dir "%dir%" ^| find "/%year%"') do move "%dir%\%%I %%J" "%year%"
%7z% a -tzip "%dir%\%year%.zip" "%year%" -mx5
set /p I="I'm about to delete the %year% folder. Hit Ctrl-C if this is a bad idea, or hit Enter to continue."
rmdir /q /s "%year%"
echo Done. w00p.
I think what you were missing is the for loop. As I've written it, it performs a directory listing, disregards anything not matching the year as the user enters it, then moves token 5* to the %year% directory for zipping.

Resources