我有一些ruby代码,我用来从FTP服务器下载csv文件。
但是,现在却没有工作,也没有显示任何错误消息。
require 'net/ftp'
require 'net/ftp'
require 'fileutils'
get '/romil' do
localfile = 'C:\\Users\\dell\\Desktop\\test1.csv'
ftp = Net::FTP.new(CONTENT_SERVER_DOMAIN_NAME)
ftp.login CONTENT_SERVER_FTP_LOGIN, CONTENT_SERVER_FTP_PASSWORD
ftp.passive = true
files = ftp.chdir('abhi/')
files = ftp.list
puts "list out of directory:"
puts files
ftp.gettextfile('test.csv', localfile, 1024)
ftp.close
end
答案 0 :(得分:0)
好的伙计们。我得到了答案, 这有点棘手, 这是工作代码:
get '/romil' do
ftp = Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME) do |ftp|
ftp.login CONTENT_SERVER_FTP_LOGIN, CONTENT_SERVER_FTP_PASSWORD
ftp.passive = true
files = ftp.chdir('abhi/')
files = ftp.list
puts "list out of directory:"
puts files
ftp.gettextfile('test7.csv')
filename = 'test7.csv'
str = ''
CSV.foreach(filename, headers: true) do |row|
status 200
headers \
"Content-Type" => "text\\plain"
str = str + row[0] + ' ' + row[1]+ "\n"
end
body str
end
end