Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

vb filename wildcard problem

$
0
0
Hello there i have the below code to search for files in folder using a wildcard

when i use this within a getfile script and then use

MsgBox(fileName)



i only get the following. mem_20130218_*.*

i am looking for a file like. mem_20130218_050013.txt

could someone show where i am going wrong please.


This code works when i specify a specific file, but i want to download all files that have ( mem_stamp_ )





Imports System Imports System.Data Imports System.Math Imports Microsoft.SqlServer.Dts.Runtime Imports System.Globalization Imports System.IO Imports WinSCP

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _ <System.CLSCompliantAttribute(False)> _ Partial Public Class ScriptMain Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

Enum ScriptResults Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure End Enum Public Sub Main() Try ' Setup session options Dim sessionOptions As New SessionOptions With sessionOptions .Protocol = Protocol.Sftp .HostName = "sftp.ftp.com" .UserName = "username" .Password = "" .SshHostKeyFingerprint = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" .SshPrivateKeyPath = ("E:\SSIS\private-key.ppk") End With Using session As Session = New Session ' Connect session.DebugLogPath = "E:\SSIS\Logfiles\winscp.log" session.ExecutablePath = "C:\Program Files (x86)\WinSCP\WinSCP.exe" session.Open(sessionOptions)

Dim stamp As String = DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture) Dim fileName As String = "Mem_" & stamp & "_*.txt" Dim remotePath As String = "/remote/" & fileName Dim localPath As String = "E:\SSIS\FTPFiles\" & fileName

' this is what it should be looking for. (mem_20130218_050013.txt)

MsgBox(fileName)



If session.FileExists(remotePath) Then

Dim download As Boolean If Not File.Exists(localPath) Then ' MsgBox(String.Format("File {0} exists, local backup {1} does not", remotePath, localPath)) download = True Else Dim remoteWriteTime As DateTime = session.GetFileInfo(remotePath).LastWriteTime Dim localWriteTime As DateTime = File.GetLastWriteTime(localPath)

If remoteWriteTime > localWriteTime Then '' MsgBox( _ ' String.Format("File {0} as well as local backup {1} exist, " & _ '' "but remote file is newer ({2}) than local backup ({3})", _ ' remotePath, localPath)) download = True Else '' Console.WriteLine( _ ' String.Format("File {0} as well as local backup {1} exist, " & _ ' "but remote file is not newer ({2}) than local backup ({3})", _ ' remotePath, localPath, remoteWriteTime, localWriteTime)) download = False End If End If

If download Then ' Download the file and throw on any error session.GetFiles(remotePath, localPath).Check()

' MsgBox("Download to backup done.") End If Else MsgBox(String.Format("File {0} does not exist yet", remotePath)) End If

session.GetFiles(remotePath, localPath).Check()

End Using

'' Return 0 Catch e As Exception MsgBox(String.Format("Error: {0}", e.Message)) Dts.TaskResult = ScriptResults.Failure '' Return 1 End Try 'Console.ReadLine() End Sub

' ''.TaskResult = ScriptResults.Success ''End Sub

End Class

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>