Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - FTP script

Reply
 
Old 01-29-2009   #1 (permalink)
James Brister


 
 

FTP script

I am trying to write a script to pull files from an ftp server. these files
are located in 2 directories. One directory will always be named "index"
(contains a csv file). The other directory will always change (contains pdf
files). It will always be in a date format of mm-dd-yyyy (i.e. 01-22-2009).
Is there a script I can write that will 1) auto-logon to the ftp server 2)
move between directories 3) copy the files from both directories to one
common location on my hard drive and 4) logout of the ftp site?



My System SpecsSystem Spec
Old 01-30-2009   #2 (permalink)
hb21l6


 
 

Re: FTP script


"James Brister" <jamesb2@xxxxxx> wrote in message
news:e73xZ0ngJHA.4408@xxxxxx
Quote:

>I am trying to write a script to pull files from an ftp server. these
>files are located in 2 directories. One directory will always be named
>"index" (contains a csv file). The other directory will always change
>(contains pdf files). It will always be in a date format of mm-dd-yyyy
>(i.e. 01-22-2009). Is there a script I can write that will 1) auto-logon to
>the ftp server 2) move between directories 3) copy the files from both
>directories to one common location on my hard drive and 4) logout of the
>ftp site?


Yes you can to all the above. but you will need to program it they way you
want it to work
Below is a sample that I use for FTP'ing files to a web server - it should
get you started.

You will have to apply your own business logic to it thou..

You have to create an FTP config file that FTP can use to do the upload.
Then execute FTP against the file.. -

Belfore you execute any script - read it, learn it, understand it!!

'============
On Error Resume Next
FTPserver = " 192.168.1.1"
FTPuser = "myuser"
strPAS = "mypass"
subject = ""
Set WshShell = CreateObject("WScript.Shell")
set fs = CreateObject("Scripting.FileSystemObject")

' the path to where the files are coming from.
root = "c:\myfilesToBeUploaded"


strPath = root + "\"
strZipFile = "peter.zip"
strFile = "peter.mdb"

templocation = WshShell.ExpandEnvironmentStrings("%temp%")
scriptname = templocation & "\upload.ftp"
numbersfile = templocation & "\info.txt"
username = "joe bloggs" '
WshShell.ExpandEnvironmentStrings("%username%")

'------------
' Create a file that later gets uploaded
'------------

set f1_out = fs.CreateTextFile(numbersfile,TRUE) ' New file
Set objFolder = FS.GetFolder(root)
f1_out.writeline("Date/time :" & NOW())
f1_out.writeline("Number of files in the upload dir :" &
objFolder.Files.Count)
f1_out.writeline("From local directory :" & root)
f1_out.writeline("Files uploaded by :" & username)

'------------
' Create new ftp script with current filenames
'------------

set startfolder = fs.GetFolder(root)
set filc = startfolder.Files ' Get file collection
set f2_out = fs.CreateTextFile(scriptname,TRUE) ' New file
f2_out.writeline(FTPuser) ' log-on with User ID
f2_out.writeline(strPAS)
f2_out.writeline("binary")
f2_out.writeline("lcd " & chr(34) & root & chr(34))
f2_out.writeline("cd " & chr(34) & subject & chr(34))
For Each fil in filc
f2_out.writeline("put " & chr(34) & fil.name & chr(34))
f1_out.writeline(chr(34) & fil.name & chr(34))
Next

f2_out.writeline("binary")
f2_out.writeline("bye") ' log off ftp session

f2_out.Close
f1_out.Close


'------------
' Build the command and start the real update
'------------
mycmd = "ftp -s:" & scriptname & FTPserver
rval = WshShell.Run("%comspec% /c " & mycmd ,1,TRUE)

'------------
' Check if proces "ftp.exe" still is active and
' if it is not clean up the scriptfile.
'------------

set wmi=getobject("winmgmts:")
wmq="select * from Win32_Process where name='ftp.exe'"
go = 0

Do While go = 0
wscript.sleep(4000)
set prs = wmi.Execquery(wmq)
if prs.count = 0 then
Set aFile = fs.GetFile(scriptname)
Set a1File = fs.GetFile(numbersfile)
' aFile.Delete
'a1File.Delete
go = 1
end if
Loop



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Logon Script Causing Laptops To Hang - Problems in script? VB Script
problem passing args to script 'There is no script engine for file extenstion' VB Script
Include another script, keep variables in included script? PowerShell
Script file has 'OS Handle' error when run from script PowerShell
Can you drag-n-drop a file on top of a PS script to run the script? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46