Link to home
Start Free TrialLog in
Avatar of magento
magento

asked on

Power shell scripting

Hi ,

I am doing a task manually.

I need a powershell to  zip file from the path
"c:\users\users\test.mdb file and then ftp the file to a linux server.
I have the server name, port , username and password.
Zip file need to have the current date and time for conventions.

Please help

Thanks,
Magento
Avatar of r3nder
r3nder
Flag of United States of America image

If you head on over to CodePlex and grab the PowerShell Community Extensions, you can use their write-zip cmdlet. also you can get the project called Alex FTPS Client that will help  you with the FTP portion
Avatar of Vasil Michev (MVP)
just call the cmdline version of winzip/winrar/whichever utility you are using, you can use get-date to generate the file name
Avatar of magento
magento

ASKER

Hi ,

I have tried the batch scripting and came so far .

Zip is working fine, but when i use ftp along then it keeps on running until i stop the script via cmd line.

@echo off
set path="C:\Program Files (x86)\WinRAR\";%path%
SET file=c:\2013_.txt
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
SET name=ftp_%mydate%_%mytime%.zip
rar a C:\%name% %file%
ftp -i -s:ftp.txt

Open in new window

***************************************
Content of FTP.txt

open test.com
support@test.com
password
lcd /D "C:\"
cd  var/tmp
binary
put 2013_.txt
bye

Can you kindly advice what is wrong with them?

Thanks
have you tried quit or bye after the ftp executes
ftp -i -s:ftp.txt
quit
Avatar of magento

ASKER

Tried that , but still it keeps on running...

C:\Expert-Exchange\DOS>ftp.bat

RAR 3.71   Copyright (c) 1993-2007 Alexander Roshal   20 Sep 2007
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Creating archive C:\ftp_2014-01-04_2118.zip

Adding    C:\Expert-Exchange\DOS\2013_.txt                            OK
Done

RAR 3.71   Copyright (c) 1993-2007 Alexander Roshal   20 Sep 2007
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Updating archive C:\ftp_2014-01-04_2118.zip

Updating  C:\Expert-Exchange\DOS\2013_.txt                            OK
Done

Open in new window

You've called your batch like the application, ftp. Since .cmd and .bat is searched before .exe, you will call your own script instead of FTP. Choose a different name for your batch, or change the call in the batch to ftp.exe.

Also note that you are currently sending the uncompressed file instead of the ZIP. However, the ZIP file name changes, and so you won't be able to use a static ftp script, unless using wildcards and mput.
Avatar of magento

ASKER

Hi ,

I used the sample file in ftp.txt because i dont know how to pass the value of the zipped file there . Please advice.

I will check ur advice above now.

Thanks
Avatar of magento

ASKER

Hi Qlemo,

Your advice worked like charm .

Now both zip and ftp working .

But i see 2 issues .

1. I am not able to ftp the zipped file ( Tried put %name%) but its not working.

2. Instead of below, can you give easy dos command to get the datetime (eg: ddmmyyyy_hhmm)

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)

Thanks,
Magento
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of magento

ASKER

This solves both the issue. Thanks again.