Solved

VB FTP on date

Posted on 2013-02-01
3
245 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 54

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 54

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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