D
D
Denis Black2017-02-10 10:05:49
ruby
Denis Black, 2017-02-10 10:05:49

RUBY - FTP File Upload, Regular Expression Pattern?

Hello everyone, there is a script that connects to FTP and pulls a specific file, how to write a regular expression so that it pulls a file according to a pattern - instead of a file date, you need a pattern:

ftp = Net::FTP.new('x.x.x.x')

  ftp.login('ololo', 'ololo')
  files = ftp.chdir('/num')
  ftp.getbinaryfile('Report_2017-02-09_15-20-30.csv', '/home/1.csv', 1024)
  ftp.close

Like this - 'Report_/(\d+)-(\d+)-(\d+)_(\d+)-(\d+)-(\d+)/.csv'? Writes there is no such file =( There
is only one file in the directory.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Cherny, 2017-02-13
@qskyhigh

Decided this way

files1 = ftp.nlst('Report*')
    report_name = Time.now.strftime("Report_%d.%m.%Y_%H.csv")
    files1.each do |file|
  ftp.getbinaryfile( file , "/home/#{report_name}", 1024)
  end

V
vsuhachev, 2017-02-10
@vsuhachev

get a list of files using ls, filter it, upload each file separately

B
bukovki, 2017-02-10
@bukovki

Report_\d+-\d+-\d+_\d+-\d+-\d+\.csv
Or do I need to parse the date?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question