Subject: Uploading Text File to FTP server in vb.net
Posted By: KiruShan Post Date: 12/6/2006 5:33:59 PM

Hi folks,

I am trying to upload a text file to a FTP server using VB.net Windows’s application.

I used the following code:

        Imports System.IO
        Imports System.Net
        Imports System.Text

        Dim localFile As String = "C:\Yserver.txt"
        Dim remoteFile As String = "ftp://ftpSERVER/test12345.txt"
        Dim username As String = "user"
        Dim password As String = "pwd"

        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 !!!")
 
When I execute these, I am getting following error

System.Net.WebException was caught
Message="The remote server returned an error: (501) Syntax error in parameters or arguments."

Please help me to overcome this.


Reply By: KiruShan Reply Date: 12/7/2006 10:12:55 AM
Moreover i m trying to connect to AS400 server , No SSL ,No proxy server..

Looking forward for ur Answer !!!
Reply By: renegade Reply Date: 12/13/2006 5:19:39 AM
I will look into this for you later Wednesday.  

What is in YServer.txt?  Is it really a text file?  If it's small enough please post the contents.


Go to topic 53563

Return to index page 95
Return to index page 94
Return to index page 93
Return to index page 92
Return to index page 91
Return to index page 90
Return to index page 89
Return to index page 88
Return to index page 87
Return to index page 86