[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB FTP on date

Posted on 2013-02-01
3
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 57

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 57

Accepted Solution

by:
Bill Prew earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 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