|
-
May 2nd, 2013, 07:50 AM
#1
Thread Starter
New Member
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:
If My.Computer.Network.Ping("ftp://00.000.000.000/", 1000) Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
For Each CurrentFile As String In IO.Directory.GetFiles("C:\kircheck\")
My.Computer.Network.UploadFile(CurrentFile, "ftp://00.000.000.000/" & "folder\folder" + New IO.FileInfo(CurrentFile).Name, "usernmae", "Password", True, 500, FileIO.UICancelOption.ThrowException)
MessageBox.Show(CurrentFile)
Next
End Sub
Private Sub Backup_Click(sender As System.Object, e As System.EventArgs) Handles Backup.Click
Dim sourcepath As String = "C:\check\*.*"
Dim DestPath As String = "C:\processed"
CopyDirectory(sourcepath, DestPath)
End Sub
Private Shared Sub CopyDirectory(ByVal sourcePath As String, ByVal destPath As String)
If Not Directory.Exists(destPath) Then
Directory.CreateDirectory(destPath)
End If
For Each file__1 As String In Directory.GetFiles(Path.GetDirectoryName(sourcePath))
Dim dest As String = Path.Combine(destPath, Path.GetFileName(file__1))
File.Copy(file__1, dest)
Next
For Each folder As String In Directory.GetDirectories(Path.GetDirectoryName(sourcePath))
Dim dest As String = Path.Combine(destPath, Path.GetFileName(folder))
CopyDirectory(folder, dest)
Last edited by Hack; May 2nd, 2013 at 07:52 AM.
Reason: Added Highlight Tags and Removed IP Address
-
May 2nd, 2013, 07:54 AM
#2
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.
-
May 2nd, 2013, 08:05 AM
#3
Thread Starter
New Member
Re: automate upload file to ftp server
thanks for removing the IP address,
-
May 2nd, 2013, 08:14 AM
#4
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
-
May 2nd, 2013, 09:50 AM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|