coderdave12
New member
- Joined
- Nov 17, 2009
- Messages
- 4
- Programming Experience
- Beginner
Hey All. Ok, I am trying to download a file from our Unix Server and I am using the code listed below. This works perfect when I am using the root credentials. Unforunantly, when I use normal crendentials it stops working on the response part, like it doesn't receive the message back. I know the normal login can FTP because I have used command line to test and it works fine. Also the directory has wide open permissions. The only thing I can tell is different is the default home directory, root is / and the normal user is nested down a few directories. Any thoughts? Thanks all
Imports System
Imports System.Net
Imports System.Data
Imports System.IO
Public Class Form1
Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
Const localFile As String = "C:\test1\Readme.txt"
Const remoteFile As String = "/httpdocs/readme.txt"
Const host As String = "ftp://yourlinkhere"
Const username As String = "yourusernamehere"
Const password As String = "yourpasswordhere"
Dim URI As String = host & remoteFile
Dim ftp As System.Net.FtpWebRequest = _
CType(FtpWebRequest.Create(URI), FtpWebRequest)
ftp.Credentials = New _
System.Net.NetworkCredential(username, password)
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
Using response As System.Net.FtpWebResponse = _
CType(ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream
Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using
End Sub
End Class
Imports System
Imports System.Net
Imports System.Data
Imports System.IO
Public Class Form1
Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
Const localFile As String = "C:\test1\Readme.txt"
Const remoteFile As String = "/httpdocs/readme.txt"
Const host As String = "ftp://yourlinkhere"
Const username As String = "yourusernamehere"
Const password As String = "yourpasswordhere"
Dim URI As String = host & remoteFile
Dim ftp As System.Net.FtpWebRequest = _
CType(FtpWebRequest.Create(URI), FtpWebRequest)
ftp.Credentials = New _
System.Net.NetworkCredential(username, password)
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
Using response As System.Net.FtpWebResponse = _
CType(ftp.GetResponse, System.Net.FtpWebResponse)
Using responseStream As IO.Stream = response.GetResponseStream
Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
responseStream.Close()
fs.Flush()
fs.Close()
End Using
responseStream.Close()
End Using
response.Close()
End Using
End Sub
End Class