Upload local file to FTP URI error

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
How can i go about uploading a local file to an ftp server? The FTP server of my website is password protected. What code can i use? I saw this code earlier:

<div style="color:black; background-color:white
<pre> <span style="color:#008000 set up request...<br/>
<span style="color:#0000ff Dim clsRequest <span style="color:#0000ff As System.Net.FtpWebRequest = <span style="color:#0000ff DirectCast(System.Net.WebRequest.Create(<span>"ftp@zencore-softworks.com/public/test.txt"), System.Net.FtpWebRequest)
clsRequest.Credentials = <span style="color:#8515ea New System.Net.NetworkCredential(<span>"username", <span>"password")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile<br/>
<span style="color:#008000 read in file...<br/>
<span style="color:#0000ff Dim bFile() <span style="color:#0000ff As <span style="color:#6f002f Byte = System.IO.File.ReadAllBytes(<span>"C:test.txt")<br/>
<span style="color:#008000 upload file...<br/>
<span style="color:#0000ff Dim clsStream <span style="color:#0000ff As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
[/code]


However i have a problem signing up the FTP to this company i work for because i recieve the following error:

System.UriFormatException: Invalid URI: The format of the URI could not be determined.<br/>
at void System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)<br/>
at void System.Uri..ctor(String uriString)<br/>
at static WebRequest System.Net.WebRequest.Create(String requestUriString)<br/>
at void ftp.MainForm.Button1Click(Object sender, EventArgs e) in C:UsersuserDocumentsSharpDevelop ProjectsftpftpMainForm.vb:line 21

That would be this line:
<span style="color:#0000ff Dim clsRequest <span style="color:#0000ff As System.Net.FtpWebRequest = <span style="color:#0000ff DirectCast(System.Net.WebRequest.Create(<span>"ftp@zencore-softworks.com/public/test.txt"),
System.Net.FtpWebRequest)
Any ideas guys?
<br/>
<br/>
<br/>
<br/>

View the full article
 
Back
Top