Solved

VB FTP on date

Posted on 2013-02-01
3
236 Views
Last Modified: 2013-03-05
I have some code to download from ftp but I need some help with a couple of bit I need to when it the first day of the month download month folder then any time after that just download the day folder which is in the month folder
Option Explicit

Const ForWriting = 2

Dim objOutStream, objjFSO, objShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutStream = objFSO.OpenTextFile("C:\temp\temp\empty.txt", ForWriting, True)
With objOutStream
    .WriteLine "USER myuser"   ' USERNAME
    .WriteLine "mypass"     ' Password
    .WriteLine "binary"
    .WriteLine "lcd /foldertocopyfrom" ' FOLDER I'm changing into
    .WriteLine "mget *"    ' Get all files with today's date in it
    .WriteLine "quit"
    .Close
End With

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /c FTP -n -i -s:" & "C:\temp\temp\empty.txt" & " " & "ftp.location.com", 0, True

Open in new window

0
Comment
Question by:beridius
  • 2
3 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
What is the folder structure on the host, and how are they named?

Will the files be placed in corresponding monthly and daily folders on the receiving client, or all in one folder?

~bp
0
 
LVL 2

Author Comment

by:beridius
Comment Utility
sorry took so long to respond  the file structure is year as 13 then month 01 folder 02 folder
in the each folder there is between 1 and 31 in some folders this depends on how many days are in a month eg 02 folder will only have 28 folders

then copied to a folder is the same format year folder and month and then day
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
Assuming the folder structure is YY\MM\DD on both the server and client, then this should be pretty close to what you described.

Option Explicit

Const ForWriting = 2
Const TempFile = "C:\temp\temp\empty.txt"

Dim objOutStream, objjFSO, objShell
Dim strYear, strMonth, strDay

strYear = Right(Year(Now()), 2)
strMonth = Right("0" & Month(Now()), 2)
strDay = Right("0" & Day(Now()), 2)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutStream = objFSO.OpenTextFile(TempFile, ForWriting, True)

objOutStream.WriteLine "USER myuser"   ' USERNAME
objOutStream.WriteLine "mypass"     ' Password
objOutStream.WriteLine "binary"
objOutStream.WriteLine "lcd /foldertocopyfrom" ' FOLDER I'm changing into
objOutStream.WriteLine "lcd " & strYear ' Year folder
objOutStream.WriteLine "cd " & strYear ' Year folder
objOutStream.WriteLine "lcd " & strMonth ' Month folder
objOutStream.WriteLine "cd " & strMonth ' Month folder

If strDay = "01" Then
   objOutStream.WriteLine "mget *"    ' Get all files with today's date in it
End If

objOutStream.WriteLine "lcd " & strDay ' Day folder
objOutStream.WriteLine "cd " & strDay ' Day folder
objOutStream.WriteLine "mget *"    ' Get all files with today's date in it

objOutStream.WriteLine "quit"
objOutStream.Close

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /c FTP -n -i -s:" & TempFile & " " & "ftp.location.com", 0, True

Open in new window

~bp
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now