Solved

VB FTP on date

Posted on 2013-02-01
3
239 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 52

Expert Comment

by:Bill Prew
ID: 38844900
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
ID: 38850713
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 52

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 38866719
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

17 Experts available now in Live!

Get 1:1 Help Now