Upload stream by ftp

1

I have this function that uploads the image of a signaturepad via ftp to a folder; the situation is that the file actually goes up, but it is not the image as such, I do not know what I can miss:

private async void onSaveAsync(object sender, EventArgs e)
{ // recuperar imagen 
Stream x;
byte[] buffer;
Stream reqStream;
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://abcde/test22.png");
try
{
x = await signature.GetImageStreamAsync(SignatureImageFormat.Png);
// this is actually memory-stream so convertible to it
var mstream = (MemoryStream)x;
//Unfortunately above mstream is not valid until you take it as byte array
stream = new MemoryStream(mstream.ToArray());
//long longitud = mstream.Length;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("user", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
buffer = BitConverter.GetBytes(mstream.Length);
mstream.Read(buffer, 0, buffer.Length);
mstream.Close();
reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Flush();
reqStream.Close();
}
catch (DirectoryNotFoundException dirEx)
{
// Let the user know that the directory did not exist.
Console.WriteLine("Directory not found: " + dirEx.Message);
}
}

Solved! The problem was that I must upload the image using the Byte format.

    
asked by Jordi Maicas Peña 16.02.2018 в 22:48
source

0 answers