I need to upload some DATA inside and FTP server.
After stackoverflow posts on how to upload FILE internally and FTP, everything works.
Now I am trying to improve my load.
Instead of collecting DATA, writing them to FILE, and then uploading the file to FTP, I want to collect DATA and upload them without creating a local file.
To do this, I do the following:
string uri = "ftp://" + ftpServerIp + "/" + fileToUpload.Name;
System.Net.FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIp + "/" + fileToUpload.Name));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
byte[] messageContent = Encoding.ASCII.GetBytes(message);
reqFTP.ContentLength = messageContent.Length;
int buffLength = 2048;
Stream strm = reqFTP.GetRequestStream();
int total_bytes = (int)messageContent.Length;
while (total_bytes > 0)
{
strm.Write(messageContent, 0, buffLength);
total_bytes = total_bytes - buffLength;
}
strm.Close();
Now the following will happen:
- I see how the client connects to the server
- File created
- no data transferred
- at some point, the thread ends with closing the connection
- If I check that the downloaded file is empty.
The DATA I want to transfer is STRING TYPE, so I do byte [] messageContent = Encoding.ASCII.GetBytes (message);
what am I doing wrong?
: ASCII.GetBytes, TEXT ?