Solved

VB FTP on date

Posted on 2013-02-01
3
243 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 53

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 53

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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 …

773 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