First I init the connection and test it with a FTP command
Sub listNewServerDWG_Click
lvDWGWeb.Clear
lvDWGWeb.AddSingleLine(DateTime.Time(DateTime.Now) & " " & DateTime.Date(DateTime.Now))
lvDWGWeb.AddSingleLine("Trying to connect to FTP...")
ftpclient.Initialize("FTP", "ftp.xx.net", 21, "x", "x")
ftpclient.TimeoutMs=5000
ftpclient.PassiveMode=True
'This checks the FTP is actually connected
ftpclient.SendCommand("NOOP","")
End Sub
Handle the response from the FTP Command:
Sub ftp_CommandCompleted ( Command As String, Success As Boolean, ReplyCode As Int, ReplyString As String)
Log("Command " & Command & " Success " & Success & " Replycode " & ReplyCode & " Replystring " & ReplyString)
If ReplyCode = 200 Then
lvDWGWeb.AddSingleLine(DateTime.Time(DateTime.Now) & " " & DateTime.Date(DateTime.Now))
lvDWGWeb.AddSingleLine("FTP NOOP command completed: " & ReplyCode)
lvDWGWeb.AddSingleLine("Looking for drawings on server...")
ListClientServerDrawings
Else
lvDWGWeb.AddSingleLine(DateTime.Time(DateTime.Now) & " " & DateTime.Date(DateTime.Now))
lvDWGWeb.AddSingleLine("FTP command NOOP failed. Try and connect again.")
End If
End Sub
Now list the files on the web-server:
Sub ListClientServerDrawings
Dim sd As Object = ftpclient.List("/drawings/client_001")
wait for (sd) FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
Dim filecounter As Int = 0
If Success Then
If Files.Length=0 Then
lvDWGWeb.AddSingleLine("server list empty 233.") '!!!< This is returned to user
ftpclient.Close
Return
End If
dwgServerList.Initialize
Dim bt (Files.Length) As Button
For f = 0 To Files.Length-1
Dim filename As String = Files(f).Name
Dim lastModDate As String=DateTime.Date(Files(f).Timestamp)
Dim lastModTime As String = DateTime.Time(Files(f).Timestamp)
dwgServerList.Add(filename & "~" & lastModDate & "~" & lastModTime)
lvDWGWeb.AddSingleLine(filename & "~" & lastModDate & "~" & lastModTime)
filecounter=filecounter+1
'Scrollview - add dynamic buttons
bt(f).Initialize("btn")
bt(f).Color=Colors.Yellow
bt(f).TextColor=Colors.Black
bt(f).Text="Test " & f
bt(f).Tag=filename
svSelectPreview.Panel.AddView(bt(f),10,10 + (f*50),200,50)
Next
Else
lvDwg.AddSingleLine("Error getting server dwg list.")
ftpclient.Close
Return
End If
ftpclient.Close
End Sub