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!

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)...

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?
 
Something like this ?
strFileName = "Document" & Year(1+Now) & Right("0" & Month(1+Now),2) & Right("0" & Day(1+Now),2) & ".xls"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
are you sure you dont mean this?


strFileName = "Document" & Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now)+ 1,2) & ".xls"
 
are you sure you dont mean this?
Absolutely. Just an example: say that today is 2005-12-31 ....
 
Here is what I have...


' 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/DocThatIneed20050920.xls", "C:\DocThatIneed.xls"
strFileName = "Document" & Year(1+Now) & Right("0" & Month(1+Now),2) & Right("0" & Day(1+Now),2) & ".xls" MySite.Disconnect

I save this to notepad with the .vbs ext and I run it but it tries to pull all of the files associated with the DocThatIneed
 
use this

strFileName = "Document" & Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now)+ 1,2) & ".xls"
 
This will give you accurate results...

Code:
Dim newDate

newDate = DateAdd("d", 1, Now())

strFileName = "Document" & Year(newDate) & ...

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
Never mind, PHV's code will work also. I didn't look at it closely enough.

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
If this is scheduled to run every day then, unless I've misunderstood, you would need something like this:

Code:
strFileName = "Document" & Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & ".xls"
MySite.Download "/InBox/" & strFileName, "C:\DocThatIneed.xls"
MySite.Disconnect

Hope this helps.
 
chmohan wrote:
>use this
>[tt]strFileName = "Document" & Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now)+ 1,2) & ".xls" [/tt]
after being pointed out the error in the formula. Is that .net again?
 
Okay....newbie here is confused... [morning]

this is what I have so far:

MySite.Host = "ftp.theirdomain.com"
MySite.Protocol = "SFTP"
MySite.Port = 22
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 = "SomeLoser"
MySite.Password = "xxxxxxx"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""
' Connect to remote server
MySite.Connect
strFileName = "Document" & Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & ".xls"
MySite.Download "/InBox/" & strFileName, "C:\DocThatIneed.xls"
MySite.Disconnect

All I did was copied this to a text file and saved it as .vbs
When I run this it connects to the ftp server and starts to download all of the DocThatIneed files instead of the one for today with todays date( DocThatIneed20050921)
am I doing something wrong.... Thanks for everyone's help.
 
would you be willing post a working script?
i.e. i am looking at file downloads at the moment and i am interested in what your MySite object refers to?
little of subject i know
 
I am not sure....the first part of the script (everything except the code ( strFileName = "Document" & Year(Now) & Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & ".xls"
MySite.Download "/InBox/" & strFileName, "C:\DocThatIneed.xls")

was created when I ran a wizard in CuteFTP while connecting to the FTP server....I just copied the script that it created.
 
I got it to work, I changed the
strFileName = "Document" ....to the actual document name.

Thanks to every1 for their help!
[2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top