vb.net - How to Request a File from FTP Using Today's Date as part of Filename? -


we have service provides several files per day pickup. each file appended today's date , hours, minutes, seconds , milliseconds stamp of time file created.

our goal download files given day regardless of time stamp. i've set following variable:

dim remotefile string = "/datafeed/sdlookup-total-" & datetime.today.year.tostring  & "-" & datetime.today.month.tostring("0#") & "-" & datetime.today.day.tostring("0#") &  ".csv.zip" 

when run console application, receive http 550 file not found because files on ftp have timestamp after day e.g.

sdlookup-total-2013-07-27_02_15_00_272.csv.zip 

the module follows:

imports system.io imports system.io.compression imports system.net imports system.net.webclient  ' module when run download file specified , save local path defined. module module1 dim today date = now() ' change value of localfile desired local path , filename  dim localfile string = "c:\foreclosurefile\sdlookoup-total-" & today.year.tostring & "-" &   today.month.tostring("0#") & "-" & today.day.tostring("0#") & ".csv.zip" ' change value of remotefile desired filename  dim remotefile string = "/datafeed/sdlookup-total-" & today.year.tostring & "-" &   today.month.tostring("0#") & "-" & today.day.tostring("0#") & ".csv.zip"  const host string = "ftp://datafeed.foreclosure.com"  const username string = "sdlookup"  const pw string = "ourpass"  dim strdownloadtemplate = "sdlookup-total-" & today.year.tostring & "-" & today.month.tostring  ("0#") & "-" & today.day.tostring("0#") & ".csv.zip"  dim strcleanfilefordts string  dim strlocalzipfile = "c:\foreclosurefile\foreclosurefull.zip"  dim strlocalcsvfile = "c:\foreclosurefile\foreclosurefull.csv"   sub main()     dim uri string = host + remotefile     dim req ftpwebrequest = ctype(ftpwebrequest.create(uri), ftpwebrequest)     req.credentials = new networkcredential(username, pw)      req.keepalive = false     req.usebinary = true     req.method = system.net.webrequestmethods.ftp.downloadfile      using response system.net.ftpwebresponse = ctype(req.getresponse,      system.net.ftpwebresponse)         using responsestream io.stream = response.getresponsestream             using fs new io.filestream(localfile, io.filemode.create)                 dim buffer(2047) byte                 dim read integer = 0                                     read = responsestream.read(buffer, 0, buffer.length)                     fs.write(buffer, 0, read)                 loop until read = 0                 responsestream.close()                 fs.flush()                 fs.close()             end using             responsestream.close()         end using         response.close()     end using     dim zippath string = "c:\foreclosurefile\"     dim extractpath string = "c:\foreclousrefile"      zipfile.extracttodirectory(zippath, extractpath)  end sub  sub processfile()      'downloaded file     dim ofile system.io.file     dim oread system.io.streamreader     dim strlocalcsvfile string = "c:\foreclosurefile\sdlookoup-total-" &      datetime.today.year.tostring & "-" & datetime.today.month.tostring("0#") & "-" &      datetime.today.day.tostring("0#") & ".csv"     dim strcleanfilefordts string = "c:\foreclosurefile\fordts\sdlookoup-total-" &      datetime.today.year.tostring & "-" & datetime.today.month.tostring("0#") & "-" &      datetime.today.day.tostring("0#") & ".csv"     dim linein string     'dim fields() string      'new file     dim onewfile system.io.file     dim owrite system.io.streamwriter      owrite = file.createtext(localfile & strcleanfilefordts)      oread = file.opentext(localfile & strlocalcsvfile)      '        strlocalcsvfile()      while oread.peek <> -1         'while oread.         linein = oread.readline()         'fixes file problem         owrite.writeline(replace(linein, """", "", 1))     end while      oread.close()     owrite.close() end sub  sub ftpfiledownload(strtfetchfile string, pathtosave string)      dim myftpwebrequest ftpwebrequest     dim myftpwebresponse ftpwebresponse     dim mystreamwriter streamwriter     dim strfullpathandfile string      strfullpathandfile = pathtosave & strtfetchfile       myftpwebrequest = webrequest.create("ftp://datafeed.foreclosure.com/datafeed/" &      strtfetchfile)      myftpwebrequest.credentials = new networkcredential("sdlookup", "ohpaih1b")      myftpwebrequest.method = webrequestmethods.ftp.downloadfile     myftpwebrequest.usebinary = true     myftpwebrequest.usepassive = true       myftpwebresponse = myftpwebrequest.getresponse()      pathtosave = "d:\test.zip"      mystreamwriter = new streamwriter(pathtosave)     mystreamwriter.write(new streamreader(myftpwebresponse.getresponsestream()).readtoend)      mystreamwriter.close()      '  litresponse.text = myftpwebresponse.statusdescription      myftpwebresponse.close()    end sub   public sub downloadfiles(byval wildcard string)     wildcard = "sdlookup-total-*.csv.zip"     dim files string() = getfiles(wildcard)     each file string in files         downloadfile(file)     next  end sub end module 

how should modify above module files containing sdlookup-total-"today'sdate".csv.zip regardless of timestamp downloaded each time module executed?


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -