Textfile up en download naar mijn website

Status
Niet open voor verdere reacties.

old Hippy

Gebruiker
Lid geworden
24 mei 2008
Berichten
911
Hallo allemaal

ik heb een textfile en wil die uploden naar een map op mijn website.
en ook weer kunnen downloden.
heb al gezocht op google

vond voor uplode dit maar krijg een foutmelding.
Code:
  Dim localFile As String = "C:\Lakshmi\test.txt"
        Dim remoteFile As String = "ftp://ftp.nl01.Mynserver.nl/test.txt"
        Dim username As String = "Username"
        Dim password As String = "Wachtwoord"

        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 !!!")

bij de regel
Request.GetRequestStream.Write(fileContents, 0, fileContents.Length)de volgende foutmelding
De externe server heeft een fout geretourneerd: (530) Niet aangemeld.


Is er iemand di mij verder kan helpen??
 
Alles werkt en is opgelost

Donwlode code

Code:
Private Function ScaricaFile(ByVal nomeFile As String) As Boolean
    Dim URI As String = "ftp://ftp.dominio.it/" + nomeFile
    Dim ftp As Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), 
FtpWebRequest)
    ftp.Credentials = New Net.NetworkCredential("utente", "password")
    ftp.Method = Net.WebRequestMethods.ftp.DownloadFile
    ftp.UseBinary = True
    Dim targetFI As New FileInfo(sPath + "\" + nomeFile)
    targetFI.Delete()
    Using response As FtpWebResponse = CType(ftp.GetResponse, FtpWebResponse)
        Using responseStream As Stream = response.GetResponseStream
            Using fs As FileStream = targetFI.OpenWrite
                Try
                    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()
                Catch ex As Exception
                    fs.Close()
                    targetFI.Delete()
                    Throw
                End Try
            End Using
            responseStream.Close()
        End Using
        response.Close()
    End Using
    Return True
End Function

Groet Old Hippy
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan