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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS for SFTP batch process

Status
Not open for further replies.

KeyserSoze1877

Programmer
Sep 6, 2001
95
0
0
US
I am using Putty SFTP to automate log tranfers on Windows.

I need a script to run with the transfer to get today's logs...

For Example: EVENTLOG0507.log

I would need to tranfer only today's file ending in MMDD. I have a batch to initiate the ftp connection and a script to automate put commands, but how do I make the put grab the right file?

How and with what?
 
Try using this function. Just pass it a date (I tested it with the Now() function and it returned 0507). I know you can do this with the Format function. I spent 2 mintues writing my own and 15 minutes researching how to use the Format function and I still couldn't get it to work right. Good Luck.

Private Function FormattedDate(ByVal dMyDate As Date) As String
Dim sMonth As String
Dim sDate As String
sMonth = Month(dMyDate)
If Len(sMonth) < 2 Then
sMonth = &quot;0&quot; & sMonth
End If
sDate = Format(Day(dMyDate), &quot;dd&quot;)
If Len(sDate) < 2 Then
sDate = &quot;0&quot; & sDate
End If
FormattedDate = sMonth & sDate
End Function
 

Ok, from pozitron you have the date part of the file name so now you need to retrieve the file from a specified directory which can be done like so...
[tt]
Private Function FindTodaysFile(FilePath As String, TodaysDate As String) As String

If Right(FilePath, 1) <> &quot;\&quot; Then FilePath = FilePath & &quot;\&quot;
FindTodaysFile = Dir(FilePath & &quot;*&quot; & TodaysDate & &quot;.log&quot;)

End Function
[/tt]

This will either return to you the file name or vbNullString if the file is not found.

Also you may want to add more error checking to this function, like checking for the path not to be a vbNullString or maybe does the directory structure exist, or perhaps add an error handler, etc.

Good Luck

 
I figured it out late yesterday, something very similar.

The SFTP program uses a batch file. I wrote a VBS to run and create the batch file with the files and date names. Works great. I have a .bat file that runs teh vbs before running the SFTP batch.
 
Hi,

I am new to using sftp2 and would like someone to help me set up a batch file to automate executions. The problem I have is it always prompt to ask for a password, therefore the automated batchfile didn't work. The manual method (interactive) is fine. I am able to log in.

If you could give me a sample of what the batchfile might look like using sftp2 or even scp2 command that would be great.

My file transfer from UNIX client to Windows server is very basic. Just connect to their server and dump the files there. The automation method is stuck on the password prompt. I have created the *.pub and authentication files already.

Thanks for the help.
 
Hi,

I have to use sFTP (putty) thru VB to ftp some files. Can anyone pls give the code in batch file to execute the ftp connection.I am new to this.. so not sure..

thanks,
pr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top