webForumDet fria alternativet

Problem med att ladda ner bilder med ftp?

.NET

0 svar · 479 visningar · startad av Dr-man

Medlem sedan juli 2002732 inlägg
Frågan#1

När jag laddar ner bilder med denna kod, så får jag dem nog nedladdade med ftp, men t.ex Windows Photo Viewer kan inte visa dem korrekt utan blir ett rött kors istället.

Här kommer koden, kan nån hjälpa mig?
Jag fattar själv inte var felet finns.

 Private Sub ButtonSave_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSave.Click
        Try
            Dim filearr() As String
            Dim filearr2() As String
            Dim filecheck As String
            Dim check, check2, j As Integer
            Dim myFtpWebRequest As FtpWebRequest
            Dim myFtpWebResponse As FtpWebResponse
            Dim myStreamWriter As StreamWriter

            Me.Cursor = Cursors.WaitCursor

            If My.Computer.FileSystem.DirectoryExists(PhotoApp.LabelOption4.Text + "\" + TreeViewftpdir.SelectedNode.Text) Then
                MsgBox("Mappen finns redan!")
            Else
                MkDir(PhotoApp.LabelOption4.Text + "\" + TreeViewftpdir.SelectedNode.Text)

                Dim ftpWebReq As Net.FtpWebRequest = CType(Net.WebRequest.Create(PhotoApp.LabelOption3.Text + "/" + TreeViewftpdir.SelectedNode.Text + "/"), Net.FtpWebRequest)
                ftpWebReq.Method = Net.WebRequestMethods.Ftp.ListDirectory
                ftpWebReq.Credentials = New Net.NetworkCredential(PhotoApp.LabelOption.Text, PhotoApp.LabelOption2.Text)
                Dim ftpWebResp As Net.FtpWebResponse = CType(ftpWebReq.GetResponse(), Net.FtpWebResponse)
                Dim streamer As IO.Stream = ftpWebResp.GetResponseStream()
                Dim reader As New IO.StreamReader(streamer)

                check = 0
                check2 = 0
                MsgBox(PhotoApp.LabelOption3.Text + "/" + TreeViewftpdir.SelectedNode.Text + "/")
                Do
                    filecheck = reader.ReadToEnd
                    If Len(filecheck) < 1 Then Exit Do
                    filearr2 = Split(filecheck, vbNewLine)
                    RichTextBox1.Text = filecheck
                    j = RichTextBox1.Lines.Count - 2
                    reader.Close()
                    Exit Do
                Loop

                For i As Integer = 0 To j

                    '   If PhotoApp.LabelOption3.Text + "/" + TreeViewftpdir.SelectedNode.Text + "/" + File.filearr2(check).get Then

                    myFtpWebRequest = WebRequest.Create(PhotoApp.LabelOption3.Text + "/" + TreeViewftpdir.SelectedNode.Text + "/" + filearr2(check))
                    myFtpWebRequest.Credentials = New Net.NetworkCredential(PhotoApp.LabelOption.Text, PhotoApp.LabelOption2.Text)
                    myFtpWebRequest.Method = Net.WebRequestMethods.Ftp.DownloadFile
                    myFtpWebRequest.UseBinary = True

                    myFtpWebResponse = myFtpWebRequest.GetResponse()
                    ' MsgBox(filearr2(check).ToString)
                    myStreamWriter = New StreamWriter(PhotoApp.LabelOption4.Text + "\" + TreeViewftpdir.SelectedNode.Text + "\" + filearr2(check))
                    myStreamWriter.Write(New StreamReader(myFtpWebResponse.GetResponseStream()).ReadToEnd)
                    myStreamWriter.Close()
                    myFtpWebResponse.Close()
                    check = check + 1
                Next
                Close()
            End If
            Me.Cursor = Cursors.Default
        Catch ex As WebException
            MsgBox("Serverinställningarna är felaktiga, kolla dem!")
        End Try
    End Sub
266 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
126 ms — deklarationer (db)
0 ms — hämta statistik (cache)
135 ms — hämta tråd, inlägg och bilagor (db)
127 ms — ändringar (db)