|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2001
Città: Catania
Messaggi: 2696
|
[VB 2010] - Controllare file su FTP
Salve ragazzi,
con questa porzione di codice riesco a collegarmi ad un mio FTP: Codice:
Public Function CheckIfFileContains(ByVal Path As String, ByVal SearchStr As String) As Boolean
Dim RetList = New List(Of String)
If (Path = Nothing Or Path = "") Then
Path = "/"
End If
_FtpRequest = CType(WebRequest.Create("ftp://" + _Host + Path), FtpWebRequest)
_FtpRequest.Credentials = New NetworkCredential(_UserName, _Password)
_FtpRequest.UsePassive = False
_FtpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails
_FtpRequest.EnableSsl = _UseSSL
_FtpRequest.Proxy = Nothing
_FtpResponse = CType(_FtpRequest.GetResponse(), FtpWebResponse)
__________________
Unisciti a noi: http://www.swproduction.altervista.org/ - http://www.enews.altervista.org/
|
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Già provato con qualcosa come :
Codice:
Public Function CheckIfFtpFileExists(ByVal fileUri As String) As Boolean
Dim request As FtpWebRequest = WebRequest.Create(fileUri)
request.Credentials = New NetworkCredential("username", "password")
request.Method = WebRequestMethods.Ftp.GetFileSize
Try
Dim response As FtpWebResponse = request.GetResponse()
' THE FILE EXISTS
Catch ex As WebException
Dim response As FtpWebResponse = ex.Response
If FtpStatusCode.ActionNotTakenFileUnavailable = response.StatusCode Then
' THE FILE DOES NOT EXIST
Return False
End If
End Try
Return True
End Function
__________________
Contattami su FaceBook --> [ ::: MarcoGG su FaceBook ::: ] Visita il mio Blog --> [ ::: Il Blog di MarcoGG ::: ] |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Jun 2001
Città: Catania
Messaggi: 2696
|
Quote:
__________________
Unisciti a noi: http://www.swproduction.altervista.org/ - http://www.enews.altervista.org/
|
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jun 2001
Città: Catania
Messaggi: 2696
|
Eccola quì fresca fresca di sviluppo:
Codice:
Public Function CheckIfFileContain(ByVal Path As String, ByVal SearchStr As String, ByVal _Username As String, ByVal _Password As String) As String
Dim Request As FtpWebRequest = WebRequest.Create(Path)
Request.Credentials = New NetworkCredential(_Username, _Password)
Request.UsePassive = False
Request.Method = WebRequestMethods.Ftp.ListDirectory
Request.EnableSsl = _UseSSL
Request.Proxy = Nothing
Dim Response As FtpWebResponse = Request.GetResponse()
Dim Streamer As Stream = Response.GetResponseStream()
Dim Reader As New StreamReader(Streamer)
Dim StrLine As String
Dim CountContains As Integer
Do
StrLine = Reader.ReadLine
If StrLine <> Nothing Then
If InStr(StrLine, SearchStr) > 0 Then
CountContains = CountContains + 1
End If
End If
Loop While StrLine <> Nothing
Select Case CountContains
Case 0
Return False
Case Else
Return True
End Select
End Function
__________________
Unisciti a noi: http://www.swproduction.altervista.org/ - http://www.enews.altervista.org/
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Ottimo, e funzia ?
__________________
Contattami su FaceBook --> [ ::: MarcoGG su FaceBook ::: ] Visita il mio Blog --> [ ::: Il Blog di MarcoGG ::: ] |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Jun 2001
Città: Catania
Messaggi: 2696
|
__________________
Unisciti a noi: http://www.swproduction.altervista.org/ - http://www.enews.altervista.org/
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 18:07.



















