views:

197

answers:

1

I wrote a sync script to upload a local file if it does not exist on the ftp server.

I want to make it more robust by ensuring that the file size on each match. This will allow the script to correct the file if it was interrupted during an upload.

What is the best way to get the file size for both the remote and local files.

I am using Net::FTP to connect to the remote server

Thank you

+2  A: 

Assuming you have direct access to the file both locally and on the remote end. You can call size on both sides.

Net::FTP.open('ftp.example.com') do |ftp|
   ...
   ftp.putbinaryfile('local.file', 'remote.file')
   remote_size = ftp.size('remote_file')
   local_size = File.size('local_file')
   <assert error condition> if remote_size != local_size
end
naven87