I think your approach seems fine, except for one thing: not all FTP servers support the SIZE command, it was introduced in the FTP Extensions , so there is no guarantee. Your exception handling is also a little rude, as you yourself noticed. I would suggest saving FTPReplyError in particular. In case this gives you an indication that SIZE is not implemented (500 or 502), you should probably rely on a backup, moreover, after the updated code:
def remote_exists?(idx) ftp = Net::FTP.new(FTP_SERVER) ftp.login begin ftp.size(idx) rescue FTPReplyError => e reply = e.message err_code = reply[0,3].to_i unless err_code == 500 || err_code == 502
A viable rollback would be to get a list of files using FTP#list , and then iterate over them and compare with idx .
source share