EndUploadFile() public method

Ends an asynchronous uploading the stream into remote file.
The object did not come from the corresponding async method on this type.-or- was called multiple times with the same . Client is not connected. The directory of the file was not found on the remote host. Permission to upload the file was denied by the remote host. -or- A SSH command was denied by the server. A SSH error where is the message from the remote host.
public EndUploadFile ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult The pending asynchronous SFTP request.
return void
                private void UploadFilesFromFilemanager()
                {
                    string destpathroot = txtRemoteFolderPath.Text;
                    if (!destpathroot.EndsWith("/"))
                    {
                        destpathroot += "/";
                    }
                    var filelist = new Dictionary<string, string>();
                    foreach (var item in lvLocalBrowser.SelectedItems.Cast<EXImageListViewItem>().Where(item => (string) item.Tag != "[..]"))
                    {
                        if ((string)item.Tag == "File")
                        {
                            filelist.Add(item.MyValue, destpathroot + Path.GetFileName(item.MyValue));
                        }
                        if ((string)item.Tag == "Folder")
                        {
                            string folder = Path.GetDirectoryName(item.MyValue);
                            folder = folder.EndsWith("\\") ? folder : folder + "\\";
                            string[] files = Directory.GetFiles(item.MyValue,
                                                                "*.*",
                                                                SearchOption.AllDirectories);

                            // Display all the files.
                            foreach (string file in files)
                            {
                                filelist.Add(Path.GetFullPath(file), destpathroot + Path.GetFullPath(file).Replace(folder,"").Replace("\\","/"));
                            }
                        }
                    }
                    long fulllength = filelist.Sum(file => new FileInfo(file.Key).Length);
                    MessageBox.Show(Tools.Misc.LengthToHumanReadable(fulllength));
                    var ssh = new SftpClient(txtHost.Text, int.Parse(this.txtPort.Text), txtUser.Text, txtPassword.Text);
                    ssh.Connect();
                    
                    ThreadPool.QueueUserWorkItem(state =>
                        {
                            long totaluploaded = 0;
                            foreach (var file in filelist)
                            {
                                CreatSSHDir(ssh, file.Value);
                                var s = new FileStream(file.Key, FileMode.Open);
                                var i = ssh.BeginUploadFile(s, file.Value) as SftpUploadAsyncResult;
                                while (!i.IsCompleted)
                                {
                                    SetProgressStatus(totaluploaded + (long)i.UploadedBytes, fulllength);
                                }
                                ssh.EndUploadFile(i);
                                totaluploaded += s.Length;
                            }
                            MessageBox.Show(Language.SSHTransfer_StartTransfer_Upload_completed_);
                            EnableButtons();
                            ssh.Disconnect();
                        });
                }