My goal is to upload a string to a txt file on an ftp server.
Here is what I have found so far:
vb Code:
Dim clsRequest As System.Net.FtpWebRequest = _ DirectCast(System.Net.WebRequest.Create(RemoteFilename), System.Net.FtpWebRequest) clsRequest.Credentials = New System.Net.NetworkCredential("usr", "pw") clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile 'write the string to a local text file Dim Report as String = "Test Report" Dim ReportFile As String = "C:\report.txt" Dim strWriter As IO.StreamWriter strWriter = New IO.StreamWriter(ReportFile) strWriter.Write(Report) strWriter.Close() ' read in file Dim bFile() As Byte = System.IO.File.ReadAllBytes(ReportFile) ' upload file Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream() clsStream.Write(bFile, 0, bFile.Length) clsStream.Close() clsStream.Dispose()
It seems pretty silly to do it like this! (write the file and then immediately read it again). Is there a way to convert a String into something that clsStream.Write will accept?
Thanks,
Dave




Reply With Quote