Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2006, 06:33 PM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Uploading Text File to FTP server in vb.net


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.


 
Old December 7th, 2006, 11:12 AM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Moreover i m trying to connect to AS400 server , No SSL ,No proxy server..

Looking forward for ur Answer !!!
 
Old December 13th, 2006, 06:19 AM
Registered User
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old July 27th, 2014, 05:16 PM
Registered User
 
Join Date: Jul 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In response to your question above. It does not matter what the contents of a file are. There is an error in the conection. check all the login details are correct for the FTP host.

Also if your uploading a file or any sort you need to make sure the file name and type are the same as the designated line of code.

example code to catch errors;

try
code to conect
code to attempt upload
code to close conection
catch ex exception
msgbox("Didnt work!")
code to close connection - disregard and try again
end try

(code may be wrong as im lazy and use memory only)
 
Old July 29th, 2014, 02:02 AM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

The exception states what is wrong, it is a 501, this typically means that the server receiving the message had an issue processing your request. Are you sure the server you are connecting to can understand ftp via http. Ftp is a protocol and the server you are sending the web request to must be able to understand it. It is also standard practice to send vague cryptic message when internal errors arise so in my opinion the best way to determine what the exception is, is to have the ftp server owner review logs to determine the root cause.

Last edited by mmorgan30; July 29th, 2014 at 02:08 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ftp text file from excel worksheet zone Excel VBA 0 July 31st, 2007 05:07 PM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
Save PDF file as text file in VB.Net kvenkatu Classic ASP Basics 0 April 7th, 2006 01:09 PM
save a PDF file as text file through VB. NET kvenkatu VB.NET 0 April 6th, 2006 12:15 PM
file transfer ftp server to a pocket PC in C# .NET g_hristodol ADO.NET 0 October 21st, 2004 06:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.