有人可以請解釋爲什麼這個塊讀操作會拋出一個EOFError?我看到它的方式,它會在完全讀取文件時結束該塊。我錯過了什麼?我該如何解決它?非常感謝。爲什麼這個FTP塊讀取操作拋出EOFError?
注意:我應該提到有時它運行良好,在其他情況下它會拋出EOFError。在同一個文件,該文件是在同一位置...
Net::FTP.open(host=ftp.address, user='********', passwd='********') do |ftp|
ftp.passive = true
files = ftp.nlst('*')
s3 = Aws::S3::Resource.new(region: 'us-east-1')
files.each do |file|
ftp.getbinaryfile(file, file, 65536) # Copies file to /tmp
UpdateVfile.loader(@company, file) # Process file from /tmp
s3_file = file + Time.zone.now.strftime("-%Y-%m-%dT%H-%M.xls")
obj = s3.bucket('mydatafeed').object(s3_file) # Build object in S3 bucket
data = ''
ftp.getbinaryfile(file, nil, 65536) do |block| <== EOFError thrown here!
data << block
end
obj.put(body: data) # Write it to S3
ftp.delete(file) # Delete the file from FTP
end
end
堆棧跟蹤:
An EOFError occurred in background at 2015.11.23 :
end of file reached
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:1112:in `readline'
-------------------------------
Backtrace:
-------------------------------
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:1112:in `readline'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:289:in `getline'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:300:in `getmultiline'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:318:in `getresp'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:351:in `block in sendcmd'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:349:in `sendcmd'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:394:in `makepasv'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:406:in `transfercmd'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:490:in `block (2 levels) in retrbinary'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:199:in `with_binary'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:488:in `block in retrbinary'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:487:in `retrbinary'
/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/ftp.rb:620:in `getbinaryfile'
/app/lib/tasks/updates_vfile.rake:40:in `block (6 levels) in <top (required)>'
FTP DEBUG_MODE OUTPUT:
put: TYPE A
get: 200 Command TYPE okay.
put: PASV
get: 227 Entering Passive Mode (75,101,155,12,5,165)
put: NLST *
get: 150 File status okay; about to open data connection.
get: 226 Closing data connection.
put: TYPE I
get: 200 Command TYPE okay.
put: PASV
get: 227 Entering Passive Mode (75,101,155,12,5,163)
put: RETR <filename redacted>
get: 150 File status okay; about to open data connection.
get: 226 Transfer complete.
...output from update processing
put: PASV
rake aborted!
EOFError: end of file reached
'ftp.debug_mode = true'請啓用它並嘗試它 –
@RajarshiDas它已被添加上面。謝謝。 –