how to automatically download files from unix to windows?

we have 2 files A.txt and B.txt at /unix/folder,every week we have to load them to \windows\folder, and send them to users.

usually, I   ftp unixserver
                 cd  /unix/folder  
                 mget *.txt "\windows\folder\*.txt"

question :
1. how to code a bat file ,when  i want to download the A.txt and B.txt , just double click the bat file?
2. how to code a bat file to upload the a specific file to unix environment or download a specific file to windows? it means give the file name as parameter.

loginID: unixuser
password: unixpass

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please see the attached script. It may be a little more heavyweight than you need (this also compares md5 hashes), but we can remove that if you wish. I will post a second commend explaining how it works.
'Remote tools installation script

'Dim Vars
    dim WshShell
    Dim fso
    Dim hFile
    Dim WshEnv
    Dim args
    Dim rFileName 'Holds the remote file name.
    Dim ftpfile
    Dim stream
    Dim command
    Dim logstream
    Dim emailSubject
'Initialize Vars
    Set args = WScript.Arguments
    Set fso = CreateObject("Scripting.fileSystemObject")
	Set WshShell = WScript.CreateObject("Wscript.Shell")
	Set WshEnv = WshShell.Environment("SYSTEM")
	'Set ftpfile = fso.GetFile("ftpscript.txt")
	'Set stream = ftpfile.OpenAsTextStream(2) '1=Read, 2=Write, 8=Append
	Set stream = fso.CreateTextFile("ftpscript.txt",True)
	Set logstream = fso.CreateTextFile("log.txt",True)
'Create download ftp script.
	logstream.WriteLine("Backup download process beginning...")
	logstream.Write("Creating FTP Download script...")
	rFileName = "backup-" & formatmonth(Month(Now)) & "-" & formatday(Day(Now)) & "-" & Right(Year(Now),2) & ".tgz"
	stream.WriteLine("cd backups")
	stream.WriteLine("GET " & rFileName)
	stream.WriteLine("GET md5.txt")
	logstream.Write("Downloading today's backup...")
'Log in with FTP and download stuff
	WshShell.Run "C:\Windows\System32\ftp.exe -s:ftpscript.txt",,True
'Run MD5 hash on downloaded file
	logstream.Write("Hashing downloaded file...")
	command = "%comspec% /c C:\Util\md5sum.exe " & rFileName & " > mymd5.txt"
	WshShell.Run command,0,True
'Compare Hashes.
	logstream.Write("Comparing hashes...")
	Dim h1 'stream for hash1 file
	Dim h2 'stream for hash2 file
	Set h1 = fso.OpenTextFile("md5.txt")
	Set h2 = fso.OpenTextFile("mymd5.txt")

	'Get the original hash from hash1 file
	Dim buffer
	buffer = h1.ReadLine()
	Dim ary
	ary = Split(buffer," ")
	Dim hash1
	hash1 = ary(0)

	'Get the new hash from hash2 file
	buffer = h2.ReadLine()
	ary = Split(buffer," ")
	Dim hash2
	hash2 = ary(0)

	If hash1 = hash2 Then
		'they match!
		logstream.WriteLine("THEY MATCH")
		emailSubject = "DevServer SUCCESSFUL backup"
		'They don't match!
		logstream.WriteLine("MATCH FAILURE!")
	End If


	'Move the files to the E drive.
	command = "%comspec% /c robocopy . F:\Backups\\ " & rFileName & " /move"
	WshShell.Run command,0,True

	logstream.WriteLine("Sending you this log file. Over and out.")

	command = "%comspec% /c C:\Util\blat.exe log.txt -to -subject """ & emailSubject & ""
	WshShell.Run command,0,True

Function formatday(strDay)
	If Int(strDay) < 10 Then
		formatday = "0" & strDay
		formatday = strDay
	End If
End Function
Function formatmonth(strMonth)
	If Int(strMonth) < 10 Then
		formatmonth = "0" & strMonth
		formatmonth = strMonth
	End If
End Function

Open in new window

This vbs script creates an FTP script on the fly, then saves it then uses ftp to download a specific file (or list if you so desire), then downloads the md5 hashes, compares them, and emails you to let you know that it was done sucessfully or not.

Here's how it works.

1. I dim all the vars.
2. I create several scripting objects (filesystem object, shell object, etc...)
3. I create the download script. This just creates the commands, in order, for the FTP program to process. You can change, add, remove commands here to suit your needs).
4. It logs into the ftp server to download stuff.
5. It runs an MD5 hash to compare the downloaded one to the original. This is where you can start deleting lines if you so please. It is more than you're asking for.
6. Next it moves the downloaded files to a backup directory. For you, this could be your distribution directory.
7. Last, it uses blat to send a log file (that it has been creating all along) to tell me what went on.

The functions at the bottom need to stay there or you might break the script.

To use the email function, you need to have a directory called C:\Util where you store blat.exe (See:

If you want to do the MD5 deal, you need to get gnucore utils and put it in C:\Util (at this point you might as well add C:\Util to the path).

I have attached a zip with a script to download and install core utils for you. It requires wget (Download from here:

I am pretty sure you feel like you just drank from the firehose by now, but let me know if you're having any issues, and I'll walk you through it.
'Dim vars
        dim x,t,m,filename
        dim wsh
        dim fso
        dim d
        dim args
        dim oFolder
        dim oFile
'Create objects
        set fso = WScript.CreateObject("Scripting.fileSystemObject")
        Set t = WScript.CreateObject("WScript.Shell")
        Set args = WScript.Arguments
        set wsh = WScript.CreateObject("WScript.Shell")
'Make sure we're in util.
'Get the file
        wscript.echo "Downloading Core Utils ..." "wget -O",1,true "unzip -o",1,true

        wscript.echo "Downloading Dependencies..." "wget -O",1,true "unzip -o",1,true

        wscript.echo "Downloading Grep..." "wget -O",1,true "unzip -o",1,true

        wscript.echo "Downloading Grep Dependencies..." "wget -O",1,true "unzip -o",1,true

        'Fix the su.exe read only bullshit "attrib -r .\bin\su.exe"

        wscript.echo "Installing binaries and dependencies..."
        set oFolder = fso.GetFolder(".\bin")
        for each oFile in oFolder.Files
                dim target
                target = t.CurrentDirectory & "\" &oFile.Name
                wscript.echo "Checking to see if " & target & " exists..."
                if fso.FileExists(target) then
'                        wscript.echo "File Exists. Removing in favor of the new file."
'                        fso.DeleteFile target
                end if
                        wscript.echo "Installing: " & oFile.Name
                        fso.CopyFile oFile.Path,target,1

        wscript.echo "Cleaning UP..."
        dim FolderNames
        FolderNames = "bin,contrib,man,manifest,share"
        dim DelFolders
        DelFolders = split(FolderNames,",")
        for each x in DelFolders
                wscript.echo "Removing folder: " & x

        dim FileNames
        FileNames = ",,,"
        dim killList
        killList = split(FileNames,",")
        for each x in killList
                wscript.echo "Removing downloaded file: " & x

        wscript.echo "Installation Complete."

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Oh... one last thing... once you get this working to solve the #1 part of your question, I'll post how to do the #2 part. It is SUPER easy once we get the #1 part setup.
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

SayYou_SayMeAuthor Commented:
thanks DrDammnit,

but it is a little bit complicated for me,
is there any other easy way to handle this?

you can try this..

create.. from notepad

with the following codes.
@ftp -i -s:"%~f0"&GOTO:EOF
!:--- FTP commands below here ---
lcd c:\MyLocalDirectory
cd  public_html/MyRemoteDirectory
mput "*.*"

and there you go.
Pieter JordaanSenior Systems Administrator - Web hosting and Network Security.Commented:
That is serious overkill

Create a file called ftpdownload.scr
and add the attached source code to it, changing the lines where needed.

Then call it using
ftp -s:ftpdownload.scr

more info:
lcd c:\
mget *

Open in new window

SayYou_SayMeAuthor Commented:
thanks guys


is it correct? based on your solution
open , what does it mean?

@ftp -i -s:"%~f0"&GOTO:EOF
open(what is it?)
lcd c:\windows\folder
cd /unix/folder
mput "*.*"

I am really confuse  
SayYou_SayMeAuthor Commented:
thanks guys

it works now
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.