Hi,

I have written an FTP application that is working with no issues.

It uploads one of 4 files to various printers on my network. I maintain a list of IP addresses.

The 4 files are printer configuration files, that contain either 1 or 3 lines of code. Very simple files.

What I want to do is hard code the contents of the files I am uploading into my application so that it doesnt have to open, read, and close the files each and every time.
Is this possible?

I understand that FTP means File Transfer Protocol, therefore the theory is that it uploads a "file".

I guess I was hoping to hook into the "buffer" part. Istead of reading something into the buffer - I pass it directly into the buffer from within my application from static strings.

Possible?

Thanks.

if you could post the "upload" part here then we might be able to give you a good solution.
Right now i would suggest to create an byte array and use writeStream.

Basically I want to take to contents of c:\test.txt and hard code it into my application.

Here is the code:

Dim localFile As String = "C:\test.txt"
        Dim remoteFile As String = "ftp://127.0.0.1/ftproot/test12345.txt"
        Dim username As String = "uploadusr"
        Dim password As String = "uploadpwd"

        Dim sourceStream As New StreamReader(localFile)
        Dim fileContents As Byte() = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd())
        sourceStream.Close()


        'Get the object used to communicate with the server.
        Dim Request As System.Net.FtpWebRequest = FtpWebRequest.Create(remoteFile)

        ' Setting Properties
        Request.Credentials = New NetworkCredential(username, password)
        Request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
        Request.Proxy = Nothing
        Request.KeepAlive = False

        ' Uploading file
        Request.GetRequestStream.Write(fileContents, 0, fileContents.Length)

        MsgBox("File Uploaded Successfully !!!")

try this then

Dim remoteFile As String = "ftp://127.0.0.1/ftproot/test12345.txt"
        Dim username As String = "uploadusr"
        Dim password As String = "uploadpwd"

        Dim fileContents As Byte() = Encoding.Default.GetBytes("your harcoded content")

        'Get the object used to communicate with the server.
        Dim Request As System.Net.FtpWebRequest = DirectCast(FtpWebRequest.Create(remoteFile), FtpWebRequest)

        ' Setting Properties
        Request.Credentials = New NetworkCredential(username, password)
        Request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
        Request.Proxy = Nothing
        Request.KeepAlive = False

        ' Uploading file
        Request.GetRequestStream.Write(fileContents, 0, fileContents.Length)

        MsgBox("File Uploaded Successfully !!!")

Worked perfectly!
Thank you.

not sure why i couldnt work that out myself :$ - but thank you anyway !

then please mark this thread as solved ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.