Upload multiple FTP files such as d * .txt to ruby

I need to connect to the ftp site and upload a bunch of files (max. 6) with the name D * .txt. could you please help me copy this into Ruby? The following code is just

ftp = Net::FTP::new("ftp_server_site")
ftp.login("user", "pwd")
ftp.chdir("/RemoteDir")
fileList= ftp.nlst
ftp.getbinaryfile(edi, edi)
ftp.close

thank

+5
source share
3 answers

The easiest way is to iterate over the list of files in fileList.

Here is an example (untested):

ftp = Net::FTP::new("ftp_server_site")
ftp.login("user", "pwd")
ftp.chdir("/RemoteDir")
fileList = ftp.list('D*.txt')
fileList.each do |file|
  ftp.gettextfile(file)
end
ftp.close

Hope this helps.

+7
source

You can get an array of file names in a directory using nlst ":

files = ftp.nlst('*.zip')

files.each do |file|
  puts file
end

#=> first.zip, second.zip, third.zip, ...
+6
source

, FTP-. ftp.list , ls -l Linux. regex, , :

ftp.list('D*.txt')[0][/.*(\d{2}):(\d{2})\s{1}(?<file>.+)$/,1]
+3

All Articles