Question: I would like to edit an image which is on a FTP server.
I use SSH.net and here is my code : 

```
using (var client = new SftpClient(ftpUploadPath, ftpPort, ftpUser, ftpPassword))
{
    client.Connect();
    using (var stream = new MemoryStream())
    {
        client.DownloadFile(fileName, stream);
        using (var img = Image.FromStream(stream, true))
        {
            img.RotateFlip(RotateFlipType.Rotate90FlipNone);
            img.Save(stream, ImageFormat.Jpeg);
            client.UploadFile(stream, fileName);
        }
    }
}

```

Everything is correct until the "client.UploadFile" which erase the image on the FTP server by a 0 octet image. The image on the FTP server is a .jpg.
I already use the "client.UploadFile" with a FileStream and it works fine. But in this case, I don't want to save the file on my IIS server, modify it an then upload it to the FTP server ...
Any idea ?

Answer: 
```
        img.Save(stream, ImageFormat.Jpeg);

        stream.Position = 0; // Reset the stream to the beginning before switching to reading it

        client.UploadFile(stream, fileName);

```
As I said above, thanks to noelicus & Thorsten, here is the solution :

```
using (var client = new SftpClient(ftpUploadPath, ftpPort, ftpUser, ftpPassword))
{
    client.Connect();
    using (var stream = new MemoryStream())
    {
        client.DownloadFile(fileName, stream);
        using (var img = Image.FromStream(stream, true))
        {
            img.RotateFlip(RotateFlipType.Rotate90FlipNone);

            using (var newStream = new MemoryStream())
            {
                img.Save(newStream, ImageFormat.Jpeg);
                newStream.Position = 0;
                client.UploadFile(newStream, item);
            }
        }
    }
}

```