title: uploading an image to FTP server in swift
body: <p>Hello everyone I'm trying to upload an image to a FTP server using an iOS app in swift.</p>
  
  <p>I used the below library.
  <a href="https://github.com/amosavian/FileProvider" rel="nofollow noreferrer">FileProvider</a></p>
  
  <p>the issue Im facing that the file uploaded to the server is having zero Bytes size. </p>
  
  <p>I checked the below questions, but I couldn't resolve my issue.</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/48090952/upload-multiple-images-to-ftp-server-in-ios">first</a></li>
  <li><a href="https://stackoverflow.com/questions/34335867/upload-file-to-ftp-server-with-swift">second</a></li>
  <li><a href="https://stackoverflow.com/questions/22754571/how-to-upload-image-either-png-or-jpg-on-ftp-server-in-ios">third</a></li>
  </ol>
  
  <p>this is the code I wrote. </p>
  
  <pre><code>var ftpProvider: FTPFileProvider?
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      let server: URL = URL(string: "ftp://x.x.x.x/")!
      let username = "xxxxx"
      let password = "xxxxxxx"
  
      let credential = URLCredential(user: username, password: password, persistence: .forSession)
  
      ftpProvider = FTPFileProvider(baseURL: server, mode: FTPFileProvider.Mode.passive, credential: credential, cache: URLCache())
  
      ftpProvider!.delegate = self
  
  }
  
  
  
   func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
      guard let chosenImage = info[UIImagePickerControllerOriginalImage] as? UIImage else{
          print("RIZK:- issue in picking images ")
          return
      }
  
      // saving the image as a file fileName.png
      _ = SavingManager.shared.saveImage(image: chosenImage)
  
      // getting the local url of the image file
      guard let localURL = SavingManager.shared.getSavedImageURL("fileName.png") else{
          return
      }
  
      //just to check if the image is being returned successfully 
      guard  let imagePreview = SavingManager.shared.getSavedImage(named: "fileName.png") else{
          return
      }
  
      //getting the file size 
      SavingManager.shared.getFileSize(localURL.path)
  
      //naming the file 
      let imageName = "\(DataManager.shared.getArchivedUser()?.lastName ?? "Guest")-\(Int(Date().timeIntervalSince1970)).png"
  
      //uploading the image 
      let progress = ftpProvider?.copyItem(localFile: localURL, to: "files/\(imageName)", overwrite: true, completionHandler: { (error) in
          if error == nil {
              print("RIZK:-- Ready to upload")
          }else{
              print("RIZK:--\(error?.localizedDescription ?? "")")
          }
      })
  
      print(progress?.fractionCompleted ?? 0)
  
  
  
      self.navigationController?.dismiss(animated:true, completion: nil)
  }
  </code></pre>
  
  <p>I also added the delegate methods but the they are not being accessed at all, </p>
  
  <p>please if anyone used this library provide help.</p>
  
  <p>thank you</p>