View Single Post
  #1 (permalink)  
Old 11-30-2008, 6:55 PM
Ahren Ahren is offline
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Nov 2008
Age: 20
Posts: 5
Reputation: 0
Ahren is on a distinguished programming path ahead
Default FtpWebRequest only has access to a specific folder

Hello,
I am currently using the below code to upload a file and display progress. It works fine except there are a few things I would like to do differently.
I am using the main FTP account for my website which has access to all of my files. I set up a different FTP login to use that only has access to a specific folder, but when I try to use it I get: Error 550 No such file or directory or access denied.

This FTP account allows access to: mywebsite.com/upload/users/ only
If strFTPAddress = mywebsite.com/upload/users/ I get error 550, I've tried a few other things too and it's told me that it's an invalid URI

Basically what I want to know is if and how I might be able to connect using my second FTP account so that I only have access to the upload/users/ directory.

Code:
Dim request As FtpWebRequest = CType(WebRequest.Create(strFTPAddress & "/" & strNetFile), FtpWebRequest)

                request.Timeout = 10000000
                request.ReadWriteTimeout = 10000000
                request.KeepAlive = False
                request.UseBinary = True
                request.UsePassive = False

                request.Credentials = New System.Net.NetworkCredential(strUserName, strPassword)
                request.Method = WebRequestMethods.Ftp.UploadFile

                Dim fileContents() As Byte

                Using s As New FileStream(strLocalFileOnDisk, FileMode.Open, FileAccess.Read)
                    ReDim fileContents(CInt(s.Length - 1))
                    s.Read(fileContents, 0, CInt(s.Length))
                End Using

                request.ContentLength = fileContents.Length

                'Try
                Dim flags As Boolean = True
                Dim currentposition As Long = 0
                Dim len As Integer = 0
                Dim requestStream As Stream = request.GetRequestStream()

                Do While (flags)

                    lblStatus.Text = "Uploading..."

                    If ((fileContents.Length - currentposition) > 200) Then
                        len = 200
                    Else
                        len = fileContents.Length - currentposition
                    End If

                    requestStream.Write(fileContents, currentposition, len)
                    currentposition = currentposition + len

                    progBar.Value = Math.Round(currentposition * 100 / fileContents.Length, 1)
                    lblLoaded.Text = Math.Round(currentposition / 1024) & "/" & Math.Round(fileContents.Length / 1024) & "kb"
                    Application.DoEvents()

                    If (currentposition >= fileContents.Length) Then
                        flags = False
                    End If
                Loop

                requestStream.Close()

                Dim response As FtpWebResponse = CType(request.GetResponse(), FtpWebResponse)

                response.Close()
Reply With Quote