Results 1 to 4 of 4

Thread: Simple File Transfer

  1. #1

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    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.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Simple File Transfer

    Quote Originally Posted by techgnome View Post
    what I don't know is if it scans subfolders
    It does have that option actually: FileSystemWatcher.IncludeSubdirectories Property

  4. #4

    Thread Starter
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    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
  •  



Click Here to Expand Forum to Full Width