|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ftpWebRequestHow can I upload some data to an FTP server, if the data is in a memory string?
Hello, Arne!
A> How can I upload some data to an FTP server, if the data is in a memory A> string? public static bool AppendFileOnServer(string memoryString, Uri serverUri) { if (serverUri.Scheme != Uri.UriSchemeFtp) { return false; } // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); request.Method = WebRequestMethods.Ftp.UploadFile; byte [] fileContents = Encoding.UTF8.GetBytes(memoryString); request.ContentLength = fileContents.Length; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential ("anonymous","jane***@contoso.com"); Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse) request.GetResponse(); Console.WriteLine("Append status: {0}",response.StatusDescription); response.Close(); return true; } Vadym,
AppendFile? I was looking for an ftp PUT. Show quote "Vadym Stetsyak" wrote: > Hello, Arne! > > A> How can I upload some data to an FTP server, if the data is in a memory > A> string? > > public static bool AppendFileOnServer(string memoryString, Uri serverUri) > { > > if (serverUri.Scheme != Uri.UriSchemeFtp) > { > return false; > } > // Get the object used to communicate with the server. > FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); > request.Method = WebRequestMethods.Ftp.UploadFile; > > byte [] fileContents = Encoding.UTF8.GetBytes(memoryString); > request.ContentLength = fileContents.Length; > > // This example assumes the FTP site uses anonymous logon. > request.Credentials = new NetworkCredential ("anonymous","jane***@contoso.com"); > Stream requestStream = request.GetRequestStream(); > requestStream.Write(fileContents, 0, fileContents.Length); > requestStream.Close(); > FtpWebResponse response = (FtpWebResponse) request.GetResponse(); > > Console.WriteLine("Append status: {0}",response.StatusDescription); > > response.Close(); > return true; > } > > -- > Regards, Vadym Stetsyak > www: http://vadmyst.blogspot |
|||||||||||||||||||||||