Computing.Net > Forums > Programming > ftp transfer in visual basic 5

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ftp transfer in visual basic 5

Reply to Message Icon

Name: legolas
Date: September 8, 2008 at 02:39:54 Pacific
OS: Win XP
CPU/Ram: 1.8 GHz AMD
Product: Dell
Comment:

Hi
I'm trying to figure out how to do a simple ftp transfer in Visual Basic 5.
I've found and tried some sample scripts without success. As I'm new to VB, I must have misunderstood how to declare them. For example one that is using Inet ActiveX control (whatever that means). According to the instructions one only needs to code:
Inet1.Protocol = icFTP
Inet1.URL = ...
but this fails already on the first line (icFTP) saying "Compile Error. Invalid outside procedure". Something must be declared before I guess...

Could someone please explain a simple way to make an ftp transfer in VB 5 (with Inet ActiveX or some other way) for a newbie like me?



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: September 8, 2008 at 08:13:19 Pacific
Reply:

>> For example one that is using Inet ActiveX control (whatever that means). <<

If you want to programme in VB I suggest you find out exactly what it means otherwise you are not going to get very far at all.

Compile Error. Invalid outside procedure means you are putting the code in the wrong place. It must be inside a function like this:

Sub FTP()

Inet1.Protocol = icFTP
Inet1.URL = ...


End Sub

You are probably putting the code in the General Section which is only for declarations and similar stuff. No code goes there.

Do a search on Google for VB FTP code. There is loads of code there that will give you an insight as to how a VB application is constructed. However, make sure your are looking at VB5 or VB6. VB.Net is a different kettle of fish altogether although to the untutored eye it looks the same.

Stuart


0

Response Number 2
Name: legolas
Date: September 8, 2008 at 10:56:25 Pacific
Reply:

Thanks for replying Stuart.
I've put the code in a sub routine. Now the error message says "Object required". So I assume some declaration is needed. Of course. Any link to a simple tutorial or sample script that explains how to do this would be most welcomed!


0

Response Number 3
Name: StuartS
Date: September 8, 2008 at 11:36:22 Pacific
Reply:

The Object required is Inet1 which is an Active X Control that needs to be put on the form.

You need to read up on how it insert Active X Controls. The VB help files have loads of information, far to extensive to put here otherwise I would end up re-writing the manual. Almost all VB applications require Active X controls.

Try this for some examples:

http://www.google.co.uk/search?hl=e...

Stuart


0

Response Number 4
Name: legolas
Date: September 12, 2008 at 06:13:46 Pacific
Reply:

OK, so I've found the following VB code browsing the net:


Private Sub cmdUpdate_Click()

' Simple FTP Sample
' This is written in VB 6. You need to include
' Microsoft Internet Transfer Control 6.0 (MSINET.OCX)
' in your code (referred to as Inet1 in this code).
'
'
'Obviously you will need to change the values used below to the
'ones that suit your needs
Inet1.AccessType = icUseDefault
Inet1...
...

I've downloaded MSINET.OCX (now installed in C:WINDOWS/system32)

On the Project meny in VB5 you can add form, module, user control and more but no ActiveX. However there is a "Component" option in which I clicked "Microsoft Internet Transfer Control 5.0". Could that refer to MSINET.OCX?

The problem is that I still get the error message "Object required, error code 424".
So I guess I haven't enabled the MSINET.OCX yet, or can the problem be that I'm running VB5 and not VB6?


0

Response Number 5
Name: StuartS
Date: September 12, 2008 at 06:43:29 Pacific
Reply:

You add Active-X components from the component option. It is a two stage process. Tick the one you require and it appears in the Tool box. With the form in front, double click the control in the tool box and it will appear on the form.

For the most part VB5 and VB6 controls are interchangeable. There are a few that are not.

>> "Microsoft Internet Transfer Control 5.0". Could that refer to MSINET.OCX? <<

It does. You can see the name of the file it referes to at the bottom of the component screen where it says location.

Stuart


0

Related Posts

See More



Response Number 6
Name: legolas
Date: September 12, 2008 at 07:22:56 Pacific
Reply:

Yes yes, now I see the icon in the toolbox. I double-click it and it appears on the form. I double-click the icon and code is generated.

Private Sub Inet1_StateChanged(...

End Sub

and I put the Inet1.Protocol... lines inside the routine, right?
But when I run the script with F5 the icon disappears on the form. How do I execute the code i.e. actually do the transfer? I don't want to click an icon to initiate the transfer, it'll be a part inside a loop and executed upon a certain condition.


0

Response Number 7
Name: StuartS
Date: September 12, 2008 at 09:11:24 Pacific
Reply:

>> and I put the Inet1.Protocol... lines inside the routine, right? <<

Wrong. If you put the code in that particular place it will never get executed until something happens to make it. That bit of code is just a stub to get you started.

To get the code to run when the application is started put in the Form Load event.

If you dont know how to do that you need to read the manual. You are not going to get very far with trial and error. VB5/6 is a little more complex that a simple VB Script.

Stuart


0

Response Number 8
Name: legolas
Date: September 17, 2008 at 10:36:51 Pacific
Reply:

OK, I have something that works now. One tricky thing was to understand how to enable the Active-X component. Thanks Stuart for taking your time to help me. I didn't have the time to RTFM.

The purpose with this script was to regularly transfer a text file over TCP/IP to a motor controller running VxWorks. In VB5 I created a simple form with three buttons: Start, Stop and Quit. The code can surely be optimized. For example I don't need to update it every 5 seconds, but if I extend the wait loop, it'll take longer time to stop it. I post the script:

Dim Test As Boolean
Dim MyTime As String
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
Form1.Visible = True
End Sub

Private Sub Quit_Click()
Form1.Visible = False
End
End Sub

Private Sub Start_Click()
Test = False
Do Until Test = True
'open and write time info to myfile'
Inet1.Protocol = icFTP
Inet1.URL = "xxx"
Inet1.UserName = "xxx"
Inet1.Password = "xxx"
Inet1.RequestTimeout = 40
Inet1.Execute , "put c:\myfile myfile"
Do While Inet1.StillExecuting
DoEvents
Loop
Inet1.Execute , "Close"
Sleep 5000
DoEvents
Loop
End Sub

Private Sub Stop_Click()
Test = True
End Sub


0

Response Number 9
Name: StuartS
Date: September 18, 2008 at 09:14:44 Pacific
Reply:

Don't terminate a VB application with the End statement. The End statement is just there for debugging purposes and will cause you problems with more comlex applications. It will cause the application to terminate without going through the correct shut-down proceedures.

The correct way to terminate a VB application is to close all open forms. The aplication will then terminate releasing all memory in doing so.

Stuart


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: ftp transfer in visual basic 5

Caller ID in Visual Basic www.computing.net/answers/programming/caller-id-in-visual-basic/11535.html

msgbox in visual basic www.computing.net/answers/programming/msgbox-in-visual-basic/10024.html

gpib programming in visual basic www.computing.net/answers/programming/gpib-programming-in-visual-basic/2145.html