|
-
Aug 10th, 2011, 10:34 AM
#1
Thread Starter
Hyperactive Member
Simple File Transfer
Hello, I've actually been using VB since VB3, but I've never gotten beyond 'novice' level. I just find it a useful tool for getting things done.
(currently using VB.NET 2010 Express)
That said, I'm trying to make a program which will be useful for many people, and there are a few features that I need that I have absolutely no idea where to start. The main of which is file transfer.
I'm trying to create a program that will keep files and folders synchronized across multiple client computers. I'm using a File system watcher to trigger events, and Using a simple System.Net.Sockets UDP client transfer (found via google) to transfer commands between it and itself on other computers.
Here's that code if it helps to know what I have
(this just sends from one textbox to another over the internet)
Code:
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Dim udpClient As New UdpClient(1024)
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Private Property testvar As Byte()
Private Sub btnwait_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnwait.Click
If BackgroundWorker1.IsBusy Then BackgroundWorker1.CancelAsync()
status.Text = "Listening"
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
testvar = receiveBytes
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
boxend.Text = Encoding.ASCII.GetString(testvar)
status.Text = "Ready"
End Sub
Private Sub btnsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsend.Click
udpClient.Connect(boxip.Text, 1024)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(boxmsg.Text)
UdpClient.Send(sendBytes, sendBytes.Length)
End Sub
By this method, I can rename, move, or delete files. I want to implement file transfer, so that whenever a new file is created, or updated, my program will automatically transfer the file to the other computers and update them there.
I would like to not have to purchase any 3rd party components, and the fewest lines of code the better. Please don't just send me to google (I've been searching for a while now) Pretend I've never programmed before when helping. I love comments!
Ok, sure I'm making myself out to be stupid, but I'm really just looking for a good explanation. Thanks in advance for any help offered.
-
Aug 10th, 2011, 12:47 PM
#2
Re: Simple File Transfer
what you're probably looking for is the FileSystemWatcher ... point it at a folder, and it'll raise events when a file is created, changed, deleted, etc. You can even filter by file extensions (or any file wildcards) ... what I don't know is if it scans subfolders... so you'll need to create one for each folder/subfolder you want to watch... which could get tricky.
http://msdn.microsoft.com/en-us/libr...emwatcher.aspx
-tg
-
Aug 10th, 2011, 12:53 PM
#3
Re: Simple File Transfer
 Originally Posted by techgnome
what I don't know is if it scans subfolders
It does have that option actually: FileSystemWatcher.IncludeSubdirectories Property
-
Aug 10th, 2011, 01:05 PM
#4
Thread Starter
Hyperactive Member
Re: Simple File Transfer
I think you guys misunderstand what I'm looking for. I already have a filesystemwatcher configured. and I know/can figure out how to read events from that. I'm trying to figure out how to send a file from one computer to another (specifically PNG images)
I want to be running the same program on 2 or more computers. when any one of them see's a new file created (via filesystemwatcher) it will automatically send the file to the other computers and they will put it in the proper folder. this way all computers are always synchronized (assuming they're all online)
the code I posted originally, is a simple UDP text transfer code, which I'm planning on using to let my program communicate with another instance of itself on another computer. so for example when a file is moved from one folder to another, I would use that code to tell the other computer to do the same change.
Does that help explain what I'm looking for?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|