Ho un problema con questo codice,facendo il Debag da vb2008 funziona ,recupera il file lo legge ecc. Ma creando il pacchetto di installazione sempre con vs2008 installandolo e provando a estrarre il file dalla mia cartella ftp del mio server non va,dove sbaglio?
Grazie!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ftp As FtpWebRequest
ftp = DirectCast(WebRequest.Create("ftp://miosito.net/file.txt"), FtpWebRequest)
ftp.Credentials = New NetworkCredential("user@io.net", "pasw")
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = WebRequestMethods.Ftp.DownloadFile
Dim sr As FileStream
Dim ftpresp As Stream
Dim bytesread As Integer
sr = New FileStream(Application.StartupPath & "\Temp\file.txt", FileMode.Create, FileAccess.Write)
'get the FTP stream
ftpresp = ftp.GetResponse.GetResponseStream()
'load the first 4096 byte 2048 1024
Dim buffer(4096) As Byte
bytesread = ftpresp.Read(buffer, 0, buffer.Length)
'loop until the stream end
While (bytesread <> 0)
'write the byte array
sr.Write(buffer, 0, bytesread)
bytesread = ftpresp.Read(buffer, 0, buffer.Length)
End While
'close obj
sr.Close()
ftpresp.Close()
If File.Exists(Application.StartupPath & "\Temp\file.txt") Then
Dim patc As StreamReader = File.OpenText(Application.StartupPath & "\Temp\file.txt")
Do While patc.Peek() >= 0
news = patc.ReadToEnd()
Loop
patc.Close()
Else
End If
If File.Exists(Application.StartupPath & "\Temp\file.txt") Then
Kill(Application.StartupPath & "\Temp\file.txt")
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub

Rispondi quotando
ma poi?
