[RESOLVED] Upload File To WebServer FTP
Ok Im Building a file storage application that saves images to a web server but I have come across an issue how do i go about uploading the files to the server how do i go about useing FTP inside of a vb application
An Example....
I have a button that opens a file select dialog you select the file it puts the location in a text box then theres a button that you click and it uploads that file to the folder on the web server.....
Im Unsure how to do this it seems simple in theory but :eek2: allot harder in real practice
Re: Upload File To WebServer FTP
Re: Upload File To WebServer FTP
yea i tryed that :) but i am getting an error
vb Code:
Option Strict Off
Imports System.Net
Module Module1
Sub Main()
Dim intChunk As Integer
Dim intoffset As Integer
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create("ftp://dlh-digital.com/public_html/images/ftptest"), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("username", "password")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes(Form5.TextBox2.Text)
' upload file...
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
intChunk = bFile.Length / 100
Form5.pbUpload.Maximum = 100
For I As Integer = 1 To 100
If intOffset + intChunk > bFile.Length Then intChunk = bFile.Length - intOffset
clsStream.Write(bFile, intOffset, intChunk)
intOffset += intChunk
Form5.pbUpload.Value = I
Next
clsStream.Close()
clsStream.Dispose()
End Sub
End Module
but on this line it errors on me
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
with the error code
The remote server returned an error: (553) File name not allowed.
ware am i going wrong....
Re: Upload File To WebServer FTP
What is the filename? What do you type in Form5.TextBox2.Text?
Is there such a file on a disk? If it exists then try to upload this file using some ftp client
Re: Upload File To WebServer FTP
yes... textbox2.text is filled by the location of the file selected from the file select dialog...
and its anyfile i try to upload with every extention so i think theres sometihng wrong someware.....
Re: Upload File To WebServer FTP
Did you try to upload this file using ordinary ftp client?
The issue may be in the ftp server itself, not your code.
Get a WORKING ftp client here
Try to upload this very file using the FTP client. Check if the server accepts it.
And does your filename contain some unusual characters? Try to rename it to 1.dat for example and try again. The remote system might not allow some unusual characters in the filename.
(mind the fact that a whitespace may be changed to %20 in the process and a percent sign % may cause troubles).
Re: Upload File To WebServer FTP
Ummmmm Yes it takes the files via filezilla....
so its not that the server dont like the file theres something else wrong with the code or something what im note sure