Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do deal with an Error when no number is provided 1

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
0
0
I am integrating FTP into my program. On the web side I intentionally removed the file I want to download to prepare an error handler in the event this may really happen. When I attempt to download the (missing) file I get the following message box:

Title of the message box: Error Copying File or Folder
Message in the message box: An error occured while copying the file.

As you can see there is no error number. This program runs unattended so I need a way to handle this. Any ideas?
Here is the code:

Code said:
Option Explicit
Dim x As Integer

Private Sub btnDownload_Click()
On Error GoTo ErrorHandler
Dim ftpFolder As Folder
Dim myShell As Shell

Set myShell = New Shell
Set ftpFolder = myShell.NameSpace("C:\atest\")
ftpFolder.CopyHere "ftp://me:password@012.123.210.21//myweb.com/myfile.html"
Exit Sub

ErrorHandler:
x = x
End Sub

Thank you.
 
Mr. Majik,

Never done what you're talking about, but I googled your problem and found this:

Dim fileSize As Long
fileSize = ftp.GetSizeByName("test123.txt")
If (fileSize < 0) Then
Text1.Text = Text1.Text & "file does not exist" & vbCrLf
Else
Text1.Text = Text1.Text & "file exists and is " _
& fileSize & " bytes in size" & vbCrLf
End If

Can something like this help you?

Ortho


[lookaround] "you cain't fix 'stupid'...
 
OrthoDocSoft,

I tried this but realized that something was missing. I Googled a line of the code and came up with one hit. After 30 days an ActiveX object needs to be purchased from a guy who calls himself ChilKat.

Any other ideas?

Thank you.
 
Although Orthodoc's implementation is somewhat questionable, the idea is sound - you need to check for the existence of the file before trying to copy it; on this occassion you've tried to cram too functionality into the ftpFolder.CopyHere line because you won't be able to respond to any errors it causes for the Shell.

Once you call the line, all the functionality is passed off asynchronously to the Shell; your program runs on to the next line (put a msgbox just before Exit Sub and you'll see what I mean). The error message you are seeing is raised and displayed by the shell. It has nothing to do with VB and is never even seen by your program.

So, as I said at the beginning, you need to check for the existence of the file before trying to copy it.
 
strongm,

Thank you for setting me on the right path. This gives me what I am looking for:

WebBrowser2.Navigate "
generates an error when the file is not there.

God bless you! :)
 
Thanks MrMajik for showing me exactly how to FTP in VB.
I have been searching for this for quite a while.

What code do you have at the receiving end?
 
Oh, for goodness sake Ted. MrMajik is simply using a minor variant my code (in the wake of a discussion in thread222-1487053). The very self-same code - thread222-1337638 - that I've pointed you to on several occassions. The minor change is that the example I provided was an upload, and MrMajik is doing a download.

And this is the code for the receiving end. At the other end is an FTP server, as we keep telling you. I know you don't like the answer, but that doesn't change the reality.
 
Sorry but I am now completely confused.

I shall rephrase my question to MrMajik.

"I would be grateful if you could tell me what you use at the other end and if it is an application written by you.
 
tedsmith,

Not sure what you are looking for so I will explain what I am building:

I have a computer that is dedicated to running a program I created that, 4 times a night, queries the web for strong companies that are publicly traded. The program picks the best stock out of a max of 12 stocks for the day.

I put up a website that shows the strongest pick for the day and tracks how long it takes the stock to move 4%.

strongm has been very helpful with the problems I encountered with the code that FTP's the daily updates from my program to the web.

Here is the website:
The picks.html page is on the receiving end. It is just a web page.

Does this answer your question?
 
Interesting. I would have though that any gain would have to be at someone elses loss. No doubt many people already do this in some form or another so, how do you make sure you don't become one of the losers?

What I am after is what is the VB6 code for BOTH ends of a FTP transfer, not using anyone elses program at all, and only working on a LAN, not the internet.

Although it must be simple, I can't understand to marry them up.

At this stage I don't want the info for a particular project but rather to satisfy my curiosity.
 
This is how I am doing it and it works. Personal info and specific paths have been replaced. You should be able to figure this out.

I have three buttons on a form; Download, Upload and Move. The code is in three parts. One part per button.

Copy down from web with error check said:
Option Explicit
Dim errorCode As Integer, PauseTime As Single, Start As Single

Private Sub btnDownload_Click()
errorCode = 0
WebBrowser2.Navigate "
'give Private Sub WebBrowser2_NavigateError time to check for errors.
PauseTime = 5
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop

Dim ftpFolder As Folder
Dim myShell As Shell
Set myShell = New Shell
Set ftpFolder = myShell.NameSpace(App.Path) 'path of my program
ftpFolder.CopyHere "ftp://mrmajik:password@123.234.210.10//public_html/myweb.com"
End Sub

Private Sub WebBrowser2_NavigateError(ByVal pDisp As Object, URL As Variant, Frame As Variant, StatusCode As Variant, Cancel As Boolean)
errorCode = StatusCode
If errorCode = 404 Then End
End Sub

The following removes the file I want to update. This is to prevent a message box asking if I want to replace the existing file (if it exists on the web)

Delete file from the web said:
Private Sub btnDeleteFromWeb_Click()
'Shell variant for deleting file from website
Dim ftpFolder As Folder
Dim myShell As Shell

Set myShell = New Shell
Set ftpFolder = myShell.NameSpace("C:\atest\")'destination foler of where the file is being moved to.
ftpFolder.MoveHere "ftp://mrmajik:password@123.234.210.10//public_html/myweb.com/myfile.html"
End Sub

And finally, uploading the file from my PC to my website:

Upload file said:
Private Sub btnUpload_Click()
'WebBrowser2 variant for uploading file to website
Dim ftpFolder As Shell32.Folder
WebBrowser2.Navigate2 "ftp://mrmajik:password@123.234.210.10//public_html/myweb.com"
Do Until WebBrowser2.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop

Set ftpFolder = WebBrowser2.Document.Folder
ftpFolder.MoveHere "C:\atest\myfile.html"
End Sub
 
>only working on a LAN, not the internet.

FTP wouldn't know or care

>the VB6 code for BOTH ends of a FTP transfer

And I'll repeat again that the client end is easy. We've repeatedly explained to you how to do the client end over and over in multiple threads now.

And I'll repeat again that, at the other end, you have to have an FTP server. That's just the way FTP works, by definition and in reality. FTP transfer works by a client sending commands to a server, and the server responding to and acting on those commands, normally resulting in a file or files being uploaded or downloaded to or from the server.

From the above you should be able to deduce that the server does most of the hard work and is a very different, significantly more complex beast than the client. Whilst is is possible to write an FTP Server from scratch, it is a non-trivial exercise (but see below for a link that may be of assistance if you really want to go in this direction) and frankly does not gain you anything. I should point out, for example, that even if the FTP Server component is just a portion of some larger program that is doing something else, it is still an FTP Server - so if you are working in an environment that bans the installation/use of FTP Servers, say, then embedding your own in your own application does not get around this embargo

RFC959, the complete definition of standard FTP, should provide you with all the information you need to understand, build and write your own basic (i.e. it the docuiment does not contain the most recent extensions to the FTP standard) FTP client and server
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top