Results 1 to 5 of 5

Thread: automate upload file to ftp server

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    4

    automate upload file to ftp server

    Hi,

    I am very new to VB.Net and my company has told me to develop- an application like whenever the scout drive is attached to network it should ping the ftpserver and upload all files to ftp server and create a new directory in the scout drive and should backup those video files. This is on client side and it should be done everyday when the scout is networked I was able to upload and create new directory and copy the files but struggling with the automate upload everyday I want some help on this.
    I know I an use windows scheduler or timer but my application should be triggered when the scout drive is attached on network. here is my code...
    vb.net Code:
    1. If My.Computer.Network.Ping("ftp://00.000.000.000/", 1000) Then
    2.             MsgBox("Server pinged successfully.")
    3.         Else
    4.             MsgBox("Ping request timed out.")
    5.         End If
    6.  
    7.         For Each CurrentFile As String In IO.Directory.GetFiles("C:\kircheck\")
    8.             My.Computer.Network.UploadFile(CurrentFile, "ftp://00.000.000.000/" & "folder\folder" + New IO.FileInfo(CurrentFile).Name, "usernmae", "Password", True, 500, FileIO.UICancelOption.ThrowException)
    9.             MessageBox.Show(CurrentFile)
    10.         Next
    11.     End Sub
    12.  
    13.     Private Sub Backup_Click(sender As System.Object, e As System.EventArgs) Handles Backup.Click
    14.  
    15.         Dim sourcepath As String = "C:\check\*.*"
    16.         Dim DestPath As String = "C:\processed"
    17.         CopyDirectory(sourcepath, DestPath)
    18.  
    19.     End Sub
    20.     Private Shared Sub CopyDirectory(ByVal sourcePath As String, ByVal destPath As String)
    21.         If Not Directory.Exists(destPath) Then
    22.             Directory.CreateDirectory(destPath)
    23.         End If
    24.  
    25.         For Each file__1 As String In Directory.GetFiles(Path.GetDirectoryName(sourcePath))
    26.             Dim dest As String = Path.Combine(destPath, Path.GetFileName(file__1))
    27.             File.Copy(file__1, dest)
    28.         Next
    29.  
    30.         For Each folder As String In Directory.GetDirectories(Path.GetDirectoryName(sourcePath))
    31.             Dim dest As String = Path.Combine(destPath, Path.GetFileName(folder))
    32.             CopyDirectory(folder, dest)
    Last edited by Hack; May 2nd, 2013 at 07:52 AM. Reason: Added Highlight Tags and Removed IP Address

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: automate upload file to ftp server

    Moved From The Codebank (which is for sharing code rather than posting questions )

    Also, I removed the IP address you put in just in case they were actual addresses.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    4

    Re: automate upload file to ftp server

    thanks for removing the IP address,

  4. #4
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: automate upload file to ftp server

    how is the drive being attached? You could try pinging the location:

    Code:
    My.Computer.Network.Ping(host name or IP address, or a System.Uri)
    I would say run it on a timer (if app will always be open) otherwise, run a service that will monitor for the connection and then upon success, open the exe and run the methods. On load, you could pass arguments to the exe to tell it to automatically upload. Creating a service is a bit more advanced if you are new, so I would concentrate on using a timer and get that working first

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    4

    Re: automate upload file to ftp server

    thanks Jay I will work on that first.....

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