Need help with FTP and VB

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
Matt
VIP - Donator
VIP - Donator
Posts: 158
Joined: Fri Jul 22, 2011 5:44 pm

Need help with FTP and VB
Matt
Hey guys, it has been a while since i last posted here on this forum... :P
But now I could really use some help :S

See, im makeing this antivirus in visual basic, which has this... kinda security system i invented xD

But when they register the product, i would like the app to access my ftp server, open the "registered.txt" file, and then add the serial that they entered to registered it...

So that when an update comes, they wont have to register the app over again :S


So the main question is, how do i edit a txt file from my ftp server, from my vb app?



Any help would be appreciated ^^
Formerly known as RyggTonning.
PM me if you have any business proposals or similar.
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: Need help with FTP and VB
smashapps
I was writing you an example but I couldn't be bothered. You can Upload and Download a file using a Webclient.

First, Import System.Net
Code: Select all
Imports System.Net
Declare Webclient
Code: Select all
 Dim client As New WebClient
Don't declare it in a Sub Function.

Next to Download the File, We use DownloadFile, also I added a RichTextBox so you can see the file and make changes and save it.

Create a Button and then on the Button1 click add this:
Code: Select all
Try
            client.DownloadFile("http://smashapps.net/test.txt", My.Computer.FileSystem.SpecialDirectories.Desktop & "/test.txt")
            RichTextBox1.LoadFile(My.Computer.FileSystem.SpecialDirectories.Desktop & "/test.txt", RichTextBoxStreamType.PlainText)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
We use the WebClient we declared, specify the address of the file, and then the location to save it. Then with the RichTextBox we don't need any dialog we use the LoadFile method but just specify that we are loading it as PlainText (otherwise it won't load as it's supposed to load Richtext not PlainText by default).

With the MsgBox, if there is an error the exception is shown to us rather then the debugging stopped etc

You can Upload a file using the Webclient and use UploadFile, but you need to set the Credentials, I've always hated FTP. You can set the credentials with:
Code: Select all
client.Credentials = New NetworkCredential("username", "password")
If I've helped please +rep :)
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

Re: Need help with FTP and VB
Martin
WOW i think that was the first explained in depth in Tutorial Requests :D
Image
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: Need help with FTP and VB
Dummy1912
smashapps wrote:
Code: Select all
client.Credentials = New NetworkCredential("username", "password")
You must be very very careful with this part
i think you must use a hard encrypt for this.
or they can access your server.

and nice tut smashapps :lol:
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: Need help with FTP and VB
smashapps
I didnt actually know it was a tutorial request otherwise I would of done more lol guess I had nothing to do I decided to help out, and yes listen to Dummy encrypt your applications or someone who see everything, you never want that to happen, even your email address :P
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
5 posts Page 1 of 1
Return to “Tutorial Requests”