|
-
Dec 20th, 2006, 06:40 PM
#1
Thread Starter
Lively Member
[RESOLVED] FTP Uploading & Checking Worked
I need to upload via FTP ALL files within a folder on server 2000) to a directory on a remote location (unix server)
I would also like some form of notification should anything go wrong.
I have either .Net 2005 or VB6 available to use for this.
How best should I accomplish this? :
FTP all files in local folder to remote folder
If any/all files were not successfully transfered then
msgbox "failed" ( I will look into emailing here though)
thanks
-
Dec 20th, 2006, 07:00 PM
#2
Re: FTP Uploading & Checking Worked
The WebClient.UploadFile method will upload a file and returns the server's response as a Byte array. You can use the IO.Directory.GetFiles method to get the file paths and then use a For Each loop to upload each file in turn.
The My.Computer.Network.UploadFile method will also upload a file and allows you to display a progress dialogue. A failure will be signified by an exception.
For more fine-grained control you can use the FtpWebRequest and FtpWebResponse classes. There are FTP libraries available on the Web that wrap these classes into a more user-friendly package. Alternatively you can create your own library or else use them directly.
-
Dec 23rd, 2006, 04:47 AM
#3
Thread Starter
Lively Member
Re: FTP Uploading & Checking Worked
still struggling on this..
Iv'e downloaded a few bits of code and tried but cant seem to find some works.?
Please could you offer working sample code or a link to code that you think looks
like it works ...
If I can get the file/s uploading I have a start to build/learn on about checking how to trap if the files did not arrive.
Cheers
-
Dec 27th, 2006, 09:35 AM
#4
Thread Starter
Lively Member
Re: FTP Uploading & Checking Worked
...Now been looking a while - Just about avery example is using C# ?
I need to connect to a server 192.168.0.1 (eg)
enter username
enter password
ftp upload a file from c:\files_to_ftp\* (eg)
to /remote/path/on/server/ (eg)
And finally I need to 'know' it got there...
Does anyone know how to do this using VB2005?
Regards
Stewart
-
Dec 27th, 2006, 04:35 PM
#5
Re: FTP Uploading & Checking Worked
VB Code:
Dim localPath As String 'Store local file path here.
Dim remoteFolder As String 'Store remote folder here.
Dim remotePath As String = IO.Path.Combine(remoteFolder, IO.Path.GetFileName(localPath))
Dim userID As String 'Store remote user ID here.
Dim password As String 'Store remote password here.
Try
My.Computer.Network.UploadFile(localPath, remotePath, userID, password)
MessageBox.Show("Upload successful.")
Catch ex As Exception
MessageBox.Show("Upload failed.")
End Try
That's just one way. As I said, you can use a WebClient or an FtpWebRequest too. Also, the UploadFile method is overloaded so you can specify additional parameters, including whether to display a progress dialogue.
-
Dec 28th, 2006, 04:38 AM
#6
Thread Starter
Lively Member
Re: FTP Uploading & Checking Worked
This errors also (Im probably doing something wrong)
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim localPath As String = "c:\testfiles\zztest.txt"
Dim remoteFolder As String = "ftp://192.168.0.1/test/share/path"
Dim remotePath As String = IO.Path.Combine(remoteFolder, IO.Path.GetFileName(localPath))
Dim userID As String = "xxxxxx"
Dim password As String = "xxxxxx"
'Try
My.Computer.Network.UploadFile(localPath, remotePath, userID, password)
MessageBox.Show("Upload successful.")
'Catch ex As Exception
'MessageBox.Show("Upload failed.")
'End Try
End Sub
I get an error on the my.computer.network line:
Webexeption was unhandled
The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
-
Jan 3rd, 2007, 11:32 AM
#7
Thread Starter
Lively Member
Re: FTP Uploading & Checking Worked
Any thoughts on why this FTP method does not work/connect ?
-
Jan 4th, 2007, 05:26 AM
#8
Thread Starter
Lively Member
Re: FTP Uploading & Checking Worked
Even the Visual Studio help shows an FTP upload sample in C# and not VB.
Is C# the way forward in visual studio and is learing VB.Net a backward step?
-
Jan 4th, 2007, 05:39 AM
#9
Thread Starter
Lively Member
Re: FTP Uploading & Checking Worked
This method also fails with the same error as above method:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using WC As New Net.WebClient
WC.Credentials = New Net.NetworkCredential("xxxxx", "xxxxx")
WC.UploadFile("ftp://192.168.0.1/test/share/zztest.txt", "c:\testfiles\zztest.txt")
End Using
End Sub
-
Jan 19th, 2007, 11:27 AM
#10
Frenzied Member
Re: FTP Uploading & Checking Worked
My.Computer.Network.UploadFile("c:\test.doc", "ftp://111.111.111.111/htdocs/test.doc", "USername", "PAssword")
This is how I got it to work. Does anyone know how to delete a file on an ftp server?
-
Jan 22nd, 2007, 02:04 PM
#11
Thread Starter
Lively Member
Re: FTP Uploading & Checking Worked
Resolved - I ended up going back to VB6 and using an inet control - MUCH easier !!
Thanks to all who tried
-
Jan 22nd, 2007, 03:03 PM
#12
Re: [RESOLVED] FTP Uploading & Checking Worked
Regarding the deleting of a file, check out:
WebRequestMethods.Ftp.DeleteFile
Google it and you will get your answer
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
|