Hello, I currently have been coding this.

Imports System.IO
Imports System.IO.Compression
Imports System.Windows.Forms
Imports System
Imports Ionic.Zip
Imports System.IO.Path
Imports System.Net.WebException
Imports System.Net
Imports System.Text
Imports System.Net.Sockets
Imports System.Security.Cryptography



Public Class Main

    ' FTP upload
    Private Sub FTPU()
        If ListBox2.SelectedItem = Nothing Then
            MsgBox("Select world.")
        Else


            Dim clsRequest As System.Net.FtpWebRequest = _
                DirectCast(System.Net.WebRequest.Create("ftp://127.0.0.1" & "example.zip"), System.Net.FtpWebRequest)
            clsRequest.Credentials = New System.Net.NetworkCredential(UserNameBox.Text, PasswordBox.Text)
            clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            ' read in file...
            Dim bFile() As Byte = System.IO.File.ReadAllBytes(c:\Example.txt)

            ' upload file...
            Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
            clsStream.Write(bFile, 0, bFile.Length)
            clsStream.Close()
            clsStream.Dispose()
            FTPU()
        End If
    End Sub

    'FTP download

    Private Sub FTPS()
        Dim line As String
        Dim ftpWebReq As Net.FtpWebRequest = CType(Net.WebRequest.Create("ftp://127.0.0.1"), Net.FtpWebRequest)

        ftpWebReq.Method = Net.WebRequestMethods.Ftp.ListDirectory

        ftpWebReq.Credentials = New Net.NetworkCredential(UserNameBox.Text, PasswordBox.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)

        ' Read first line.
        line = reader.ReadLine

        ' Loop over each line in file, While list is Not Nothing.
        Do While (Not line Is Nothing)
            ' Add this line to list.
            Me.ListBox1.Items.Add(line)
            ' Display to console.
            Console.WriteLine(line)
            ' Read in the next line.
            line = reader.ReadLine
        Loop

        reader.Close()
        'clean up
        line = ""
        ftpWebReq = Nothing
        streamer = Nothing
        reader = Nothing



    End Sub
End Class

It uploads files fine.

But, I want to have the UsernameBox.text and PasswordBox.text on another form, so if the login fails, then it exits the application.

If login is successful, then form2 loads and they can press the upload button.

Sorry if I'm being vague, its 5:30am.

Thank you and again, sorry.

Didn't read your code but I think i have a similiar situation.

Show the form as a dialog. Set the result as Dialog result to Cancel if it fails. Ok on success.

Create a ReadOnly Property for Username and Password to read if the Dialog result is OK. If The result is Cancel exit the application.

Didn't read your code but I think i have a similiar situation.

Show the form as a dialog. Set the result as Dialog result to Cancel if it fails. Ok on success.

Create a ReadOnly Property for Username and Password to read if the Dialog result is OK. If The result is Cancel exit the application.

That sounds like it should work. Unfortunately, I'm not very good at coding just yet, I've really only just started making applications that are useful.

Do you have any tutorials or anything?

I don't see anywhere one here about a username and password. Where are you validating that?

Unhnd Exception, at line 26.

clsRequest.Credentials = New System.Net.NetworkCredential(UserNameBox.Text, PasswordBox.Text)

If the credentials are not correct the server should return a 530 error code if the username and password was wrong. Put Everything in a try catch block. Look for a .net.web exception.

If you get a exception than cancel. You can look into the .net.web exception class for more info.


One thing you could do is in your try catch, set the forms dialog result to cancel if an error is caught.


If the dialog is cancel then exit the app.


Set the Dialog to ok after everything is processed.
me.dialogresult = Ok


You Will need to read about .net exceptions and handle your own error handling so you don't exit the app if it was just a connection error or something other than a log in falure.


Create a property


ReadOnly Property Username() as string
Get
return username.text
end get


Do the same for password.

if Dialog Ok then read the properties

try
'process your code
me.dialogresult = dialogresult.ok
catch ex as exception
'catch and handle your error
me.dialog result = dialogresult.cancel
finally
'clean up your resources
end try

if my.xform.showdialog = cancel then 'exit the app

'continue on with what ever else you where doing

Hmm, I think I got it to work, I will post the source once I get it working so everyone who searches this (Not alot, but might save someone else from asking the same question).


Thank you.

This question has already been answered. Start a new discussion instead.