Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.1k views
in .NET FTP by (162k points)
Here's the Demo.cs in the distro converted to VB.

You'll need to reference the edtFTPnet DLL of course to compile this.

Imports System
Imports EnterpriseDT.Util.Debug
Imports EnterpriseDT.Net.Ftp

Public Class Demo

 Public Shared Sub Main(ByVal args() As String)
   If args.Length < 3 Then
     Usage()
     System.Environment.Exit(1)
   End If
   Dim log As Logger = Logger.GetLogger(GetType(Demo))
   Dim host As String = args(0)
   Dim user As String = args(1)
   Dim password As String = args(2)
   Logger.CurrentLevel = Level.ALL
   Dim ftp As FTPClient = Nothing
   Try
     log.Info("Connecting")
     ftp = New FTPClient (host)
     log.Info("Logging in")
     ftp.Login(user, password)
     log.Debug("Setting up passive, ASCII transfers")
     ftp.ConnectMode = FTPConnectMode.PASV
     ftp.TransferType = FTPTransferType.ASCII
     log.Debug("Directory before put:")
     Dim files As Array = ftp.Dir(".", True)
     Dim i As Integer = 0
     While i < files.Length
       log.Debug(files(i))
       i += 1
     End While
     log.Info("Putting file")
     ftp.Put("readme.txt", "readme.txt")
     log.Debug("Directory after put")
     files = ftp.Dir(".", True)
     i = 0
     While i < files.Length
       log.Debug(files(i))
       i += 1
     End While
     log.Info("Getting file")
     ftp.Get("readme.txt.copy", "readme.txt")
     log.Info("Deleting file")
     ftp.Delete("readme.txt")
     log.Debug("Directory after delete")
     files = ftp.Dir("", True)
     i = 0
     While i < files.Length
       log.Debug(files(i))
       i += 1
     End While
     log.Info("Quitting client")
     ftp.Quit()
     log.Info("Test complete")
   Catch e As Exception
     log.Debug(e.StackTrace)
   End Try
 End Sub

 Public Shared Sub Usage()
   System.Console.Out.WriteLine("Usage: Demo remotehost user password")
 End Sub
End Class

4 Answers

0 votes
by (180 points)
Hi,

Thanks for the example.

Is there some way to access the text of the logger responses? I would like to have all ftp server messages, etc. be outputted to an on-screen textbox so the user can follow what is going on as it happens. Is the logger the way to do this or are there message functions that do this within the FTPConnection object?

I know I could write to the log file and re-load and read it but that's a pretty lame hack :)

Thanks,

Tim
0 votes
by (162k points)
Look at FileAppender.cs. It is pretty trivial to write an appender that stores the messages rather than writes them to a file.
0 votes
by (180 points)
Hi,

Thanks for the suggestion. I have two questions (maybe they are the same question)

(1) I can create a fileAppender, but I am finding it difficult to connect that to the ftpconnection object.
(2) In reference to the previous code (an my original question) - I don't see where incoming messages from the server show up - all the of log messages in the sample code above are manually entered (e.g. "log.Info("Getting file")") - How do we see what the server is actually saying? Like if I send it the wrong path or password, where does the return error message get stored and how do I access it. The API pdf shows how this works, but doesn't have any code. I'm mainly a VB programmer so it is not so easy for me to convert the code in the general documentation. Any chance you could post a quick code sample?

Thanks!

Tim
0 votes
by (162k points)
If you just want the message that are sent back and forth, look at the CommandSent and ReplyReceived events.

Categories

...