Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for auto date change

Status
Not open for further replies.
Sep 24, 2003
34
US
I need to connect to an FTP site(via FTP Client) everyday to download a file...(I have this part)...
but the file name is (Document20050920.xls....for example...where the 20050920 is yearmonthday) Is there syntax to automatically change the date to the next day (I want to schedule the job to run)
so that the next automatic download from the FTP server will pull Document20050921?
 
Rick,

Here is what I had before your code....I am not sure where to place your code. Any other changes? Here is what I have so far.

MySite.Host = "domainthatIwanttoconnectTO.com"
MySite.Protocol = "SFTP"
MySite.Port = xx
MySite.Retries = 30
MySite.Delay = 30
MySite.MaxConnections = 2
MySite.TransferType = "AUTO"
MySite.DataChannel = "DEFAULT"
MySite.AutoRename = "OFF"
' WARNING!!! SENSITIVE DATA: user name and password.
MySite.Login = "Somebody"
MySite.Password = "xxxxxxxxxxxxxxx"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""
' Connect to remote server
MySite.Connect
MySite.Download "/InBox/Document20050920.xls", "C:\Document20050920.xls"
filename = "Document" & today.adddays(1).tostring("yyyyMMdd") & ".doc"
MySite.Disconnect
 
Code:
filename = "Document" & today.adddays(1).tostring("yyyyMMdd") & ".xls"
MySite.Download "/InBox/" & filename, "C:\" & filename

If today's date is 9/20/2005, this will attempt to download the file called "Document20050921.xls", if you don't want to download the file for tomorrow's day, remove the ".adddays(1)" portion.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I ran the following code and it started to download every file named "Documentxxxxxxx" xxxxxxx = yearmonthdate

I am not sure what I am missing for it to download the doc that I need for today and then once I schedule the job to run...I want it to pick the correct doc for tomorrow.


Thanks.

' Initialize remote server host name, protocol, port, etc.
MySite.Host = "domainthatIwanttoconnectTO.com"
MySite.Protocol = "SFTP"
MySite.Port = xx
MySite.Retries = 30
MySite.Delay = 30
MySite.MaxConnections = 2
MySite.TransferType = "AUTO"
MySite.DataChannel = "DEFAULT"
MySite.AutoRename = "OFF"
' WARNING!!! SENSITIVE DATA: user name and password.
MySite.Login = "Somebody"
MySite.Password = "xxxxxxxxxxxxxxx"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""
' Connect to remote server
MySite.Connect
MySite.Download "/InBox/" & filename, "C:\ftp\docs" & filename
filename = "Document" & today.adddays(1).tostring("yyyyMMdd") & ".xls"
MySite.Disconnect
 
you need to set the filename variable BEFORE you download the file.

Code:
'this first:
filename = "Document" & today.adddays(1).tostring("yyyyMMdd") & ".xls"

'Then download:
MySite.Download "/InBox/" & filename, "C:\ftp\docs" & filename

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
' Initialize remote server host name, protocol, port, etc.
MySite.Host = "domainthatIwanttoconnectTO.com"
MySite.Protocol = "SFTP"
MySite.Port = xx
MySite.Retries = 30
MySite.Delay = 30
MySite.MaxConnections = 2
MySite.TransferType = "AUTO"
MySite.DataChannel = "DEFAULT"
MySite.AutoRename = "OFF"
' WARNING!!! SENSITIVE DATA: user name and password.
MySite.Login = "Somebody"
MySite.Password = "xxxxxxxxxxxxxxx"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""
' Connect to remote server
MySite.Connect
filename = "Document" & today.adddays(1).tostring("yyyyMMdd") & ".xls"
MySite.Download "/InBox/" & filename, "C:\ftp\docs" & filename
MySite.Disconnect


it still downloads all of the files with "Document"

sorry for the confusion.
 
put the cursor (the blinking 'I' bar) on the line that says:

MySite.Download "/InBox/" & filename, "C:\ftp\docs" & filename

That should make that line appear with a dark red background

Then run the application. The program will stop on that line, and it will have a bright yellow background.

If the immediate window is not open, open it by going to the debug menu -> Windows -> Immediate.

In the Immediate window, type:

?Filename

Copy what ever it spits out, and post it here.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I am using word pad to write my program in. Should I be using something else to have all of the options that you mentioned?
 
I am writing this one script in notepad and saving it as .vbs and then I plan to use windows scheduler to run this one app. I am new at this and I was given this project to find out how to transfer the files automatically. So I am only doing this one file...
I guess I will download the Sharp Dev
 
Ahh, in that case, I think you are looking in the wrong place. VB Script and windows scripting are entirely different beasts then .Net.

I would point you to the forum search function at the top of the page, type in vbs or windows script and follow the link to one of those forums, they will be able to guide you much better.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top