Last Time this code is working but now i am not able to download the bhav file from the NSE web site
blow the code i am using
Dim WC As New WebClient
Dim DD, MMM, YYYY As String
Dim FileName As String
Dim FileURL As String
Dim ZipPath As String
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
DD = DateTimePicker1.Value.ToString("dd")
MMM = UCase(DateTimePicker1.Value.ToString("MMM"))
YYYY = DateTimePicker1.Value.ToString("yyyy")
If UCase(DateTimePicker1.Value.ToString("dddd")) = "SATURDAY" Then Exit Sub
If UCase(DateTimePicker1.Value.ToString("dddd")) = "SUNDAY" Then Exit Sub
FileName = "cm03AUG2021bhav.csv.zip"
FileName = FileName.Replace("03AUG2021", DD & MMM & YYYY)
FileURL = "https://www1.nseindia.com/content/historical/EQUITIES/2023/JAN/cm02JAN2023bhav.csv.zip"
FileURL = FileURL.Replace("2023", YYYY)
FileURL = FileURL.Replace("JAN", MMM)
FileURL = FileURL.Replace("02", DD)
ZipPath = App.Dir.BhavPath & "\" & FileName
WC.DownloadFile(FileURL, ZipPath)
i am trying to download the file but not downloading now
getting the error in vb.net
The remote server returned an error: (403) Forbidden.
url - https://www1.nseindia.com/content/historical/EQUITIES/2023/JAN/cm02JAN2023bhav.csv.zip
getting error in google crome
Access Denied
You don't have permission to access "http://www1.nseindia.com/content/historical/EQUITIES/2023/JAN/cm02JAN2023bhav.csv.zip" on this server.
Reference #18.83e83217.1672846762.b1fb356
i am able to download from this link from google chrome
https://www1.nseindia.com/products/content/all_daily_reports.htm
Related
I am calling SSRS from SSIS Script task and stores the report in PDF format.
Below is my code in Script task:
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
loRequest.Timeout = 7200
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
End Sub
Public Sub Main()
Dim url, destination, Todaydate, FolderName, DestinationError As String
Try
Todaydate = Dts.Variables("TodayDate").Value.ToString
FolderName = Dts.Variables("FolderName").Value.ToString
destination = Dts.Variables("DestFolder").Value.ToString + "\" + Todaydate + "\" + FolderName + "\" + Dts.Variables("CurrentReport").Value.ToString + "_" + Dts.Variables("CurrentParamID").Value.ToString + "_" + Format(Now, "yyyyMMdd") + ".pdf"
url = "http://server-name/ReportServer?/ReportPath/AUTOMATED/" + Dts.Variables("CurrentReport").Value.ToString + "&rs:Command=Render&Param=" + Dts.Variables("CurrentParamID").Value.ToString + "&rs:Format=PDF"
Dts.Variables("User::GeneratedPDFpath").Value = destination
SaveFile(url, destination)
End Try
Dts.TaskResult = ScriptResults.Success
End Sub
This code works fine and generates report in PDF. But, sometimes it generates PDF file with size of 0 KB. When that PDF is opened, it displays an error for Corrupted File.
P.S. I have used Execute SQL task which stores a resultset. Using that resultset in Foreach Loop container, it initially created folder for today's date and stores the respective PDF in folder.
Would appreciate if someone could provide some help on this.
I have a problem with my FTP upload and I hope you can help me. I'm trying create folders and then upload files to them. What my program should do is checking if a folder already exists, and if not, create a new one with the name checked before. The program runs fine, except for the error described below.
My Problem:
I want to upload a folder called ghandle -> works as intended.
After that, I want to upload a folder called handle -> doesn't work, because the .Contains method that checks the folders on the FTP server, finds ghandle and stops, because ghandle contains handle.
Are there other options like .Contains which will just check for whole words or exact matches?
Here is my source code:
Dim dirname = Path.GetFileNameWithoutExtension(openFileDialogHtml.FileName) & "_files"
Dim ftp = "ftp://" & ftp_address.Text & "/"
Dim user = ftp_user.Text
Dim pass = ftp_password.Text
Dim request As Net.FtpWebRequest = Net.FtpWebRequest.Create(ftp)
Dim creds As Net.NetworkCredential = New Net.NetworkCredential(user, pass)
request.Credentials = creds
Dim resp As Net.FtpWebResponse = Nothing
request.Method = Net.WebRequestMethods.Ftp.ListDirectoryDetails
request.KeepAlive = True
Using resp
resp = request.GetResponse()
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.ASCII)
Dim s As String = sr.ReadToEnd()
If Not s.Contains(dirname) Then
request = Net.FtpWebRequest.Create(ftp & dirname)
request.Credentials = creds
request.Method = Net.WebRequestMethods.Ftp.MakeDirectory
resp = request.GetResponse()
MsgBox("Created folder " & dirname)
Else
MsgBox("Folder " & dirname & " already exists!")
End If
End Using
Thanks in advance
First, use ListDirectory, not ListDirectoryDetails. The ListDirectory returns plain names only, what is enough for your purpose and easy to parse.
Then just split the output to an array of individual file names, using the String.Split method:
Dim names As String() =
sr.ReadToEnd().Split(
New Char() {vbCr, vbLf}, StringSplitOptions.RemoveEmptyEntries)
And use the IEnumerable.Contains extension method to check for given file name:
If Not names.Contains(dirname) Then
I'm trying to create a text file and write data to it, simple right.
Well it's not working and I've looked everywhere for it but can't find an answer.
When it gets to the CreateTextFile() method it throws a path not found error. But I've made sure the path is valid and exists.
'Create a text file
Private Sub OpenFile()
Dim filePath As String
Dim fileName As String
Dim fullPath As String
Const ForAppending = 8, TristateFalse = 0
Dim curDate As Date
Dim strDate As String
curDate = Date
strDate = CStr(curDate)
fileName = "DCSSInputLitigation_" & "(" & strDate & ")" & ".txt"
filePath = "C:\TempFolder\"
Set fs = CreateObject("Scripting.FileSystemObject")
fullPath = fs.BuildPath(filePath, fileName)
Set fWriter = fs.CreateTextFile(fullPath)
End Sub
When I hard code the path in the method it works but not when I use variables. Any Ideas?
Set fWriter = fs.CreateTextFile("C:\TempFolder\test.txt")
When you get the date as follows:
strDate = CStr(curDate)
you are adding / into the file name and the string value for fullPath which you create is:
C:\TempFolder\DCSSInputLitigation_(6/12/2014).txt
File names cannot have / in them on Windows so you are running into problems here.
You can either format the date or replace the / like:
strDate = replace(CStr(curDate),"/","-")
strDate = Format(curDate,"dd-mm-yyyy")
Either will work.
I am writing the code using vb.net for file transfer from remote machine to local machine with out using any third party tools
This my code
Dim reqFTP As FtpWebRequest
Dim filepath As String
Dim filename As String
Dim filename1 As String
Dim ftpserverip As String
Dim ftpuserid As String
Dim ftpPassword As String
Try
filename1 = TxtRemoteFile.Text
filepath = TxtLocalFile.Text
filename = Locfname.Text
ftpserverip = TxtServerIP.Text
ftpuserid = TxtUserName.Text
ftpPassword = TxtPwd.Text
Dim outputStream As FileStream = New FileStream((filepath + ("\\" + filename)), FileMode.Create)
reqFTP = CType(FtpWebRequest.Create(New Uri(("ftp://" _
+ (ftpserverip + ("/" + filename1))))), FtpWebRequest)
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
reqFTP.UseBinary = True
reqFTP.Credentials = New NetworkCredential(ftpuserid, ftpPassword)
Dim response As FtpWebResponse = CType(reqFTP.GetResponse, FtpWebResponse)
outputStream.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
but am getting error like" remote server returned error :(550) fi
I had the same issue. I was not including httpdocs in the remote path.
Example:
ftp://ftp.websitename.com/httpdocs/filenametocopy.txt
System.Net.WebRequest.Create("ftp://ftp.websitename.com/httpdocs/filenametocopy.txt")
Permission was denied because i was trying to write the file outside the root directory.
I am trying to upload a file to Mainframe machine from my VB.net application. I am getting the following error.
The remote server returned an error: (501) Syntax error in parameters or arguments
Below is my code. Any help will be appreciated.
Dim urlHost As String = "ftp://" + FWFTP.Default.TargetFTPHost.ToString()
Dim url As String = "ftp://" + FWFTP.Default.TargetFTPHost & "/" & FWFTP.Default.TargetFolder & "/" & fileName
Dim clsRequest As System.Net.FtpWebRequest = CType(WebRequest.Create(url), FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential(FWFTP.Default.FTPUserName.ToString(), FWFTP.Default.FTPPassword.ToString())
clsRequest.Proxy = Nothing
Dim target As New Uri(urlHost)
Dim iphe() As System.Net.IPAddress = System.Net.Dns.GetHostAddresses(target.Host)
If My.Computer.Network.Ping(iphe(0).ToString, 200) = False Then
MsgBox("Ping: " + urlHost + ":" + iphe(0).ToString + " Failed")
'ElseIf FTPSite <> "" Then
End If
clsRequest.KeepAlive = False
clsRequest.UseBinary = False
clsRequest.UsePassive = True
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes(fullPath)
' upload file...
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
When you say 'mainframe', it wouldn't be AS/400 by any chance?
http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/6c621557-62af-4d4a-9afd-e5b127c380f4
In particular, see the suggestion by FTPOdyssey in this thread
When you use System.Net.WebClient or FtpWebRequest and you access a Z/Os mainframe if you want to access the following ftp url (notice the # in the password):
ftp://userid:p#ssword#host/pub/data/msg.log
You must do the following:
ftp://userid:%40ssword#host/%2Fpub/data/msg.log
This should work with either download or upload.