public void DownloadAttachment(Attachment attachment, string localPath) { Procedure procedure = (from p in appManager.ApplicationDb.Procedures from a in p.Attachments where a.Id == attachment.Id select p).FirstOrDefault(); MedicalRecord medicalRecord = (from m in appManager.ApplicationDb.MedicalRecords from p in m.Procedures where p.Id == procedure.Id select m).FirstOrDefault(); Patient patient = (from p in appManager.ApplicationDb.Patients from m in p.MedicalHistory where m.Id == medicalRecord.Id select p).FirstOrDefault(); string medicalRecordPath = String.Format("{0}/{1}", patient.Ssn, medicalRecord.Id); string ftpFileName = String.Format("{0}/{1}_{2}_{3}", medicalRecordPath, procedure.Id, attachment.Id, attachment.File); FTPConnection ftp = new FTPConnection("193.224.69.39", "balu", "szoftech", "hubasky/attachments"); ftp.DownloadFile(ftpFileName, localPath); }