Create an FTP component (get) with VB

Source: Internet
Author: User
Tags ftp
Basic steps:
1, with a internetopen call to set up the environment.
2, call the InternetConnect function to connect with the host.
3, call FtpGetFile to reach the file.
4, close the 1th, 2 steps to create the handle, with the InternetCloseHandle function.
Now take a closer look at each step:
1, the environment is set by calling the InternetOpen function. The following is a declaration of VB-specific invocation of this function:
Private Declare Function internetopen Lib "Wininet.dll" Alias "Internetopena" _
(ByVal sagent As String, ByVal Laccesstype as Long, ByVal Sproxyname As String, _
ByVal Sproxybypass as String, ByVal lflags as long) as long
Parameter sagent is used to specify the application or entity that calls the WinInet function. To achieve the goal, you can set up FTP control.
Parameter Laccesstype Specifies whether we are connected directly to a host or using a proxy server. If you pass a value of 1, you are connected directly to the host. If 3 is passed, the proxy server is passed. If you pass 0, the connection will be based on
Registry values under Hkey_current_usersoftwaremicrosoftwindowscurrentversioninternet settings
ProxyEnable, ProxyServer and ProxyOverride.
We can use parameters Sproxyname and Sproxybypass instead of registering settings to provide proxy servers and IP addresses and names that do not use proxy servers. The basic format for listing agents is Rotocol=protocol://proxy_name:access_port? For example, to specify that port 21 on Proxy1 is a proxy server, use ftp=ftp://proxy1:21 as the sproxyname. Want to spare the OV? Start any host, sproxybypass string should be ov*?
Finally, Lflags is used to show the different choices that affect the result of the function. In our example, we pass 0.
So, when you open an Internet session without using a proxy, we call this:
Lnginet = InternetOpen ("FTP control", 1, vbNullString, vbNullString, 0)
If the function call fails, lnginet is 0. Otherwise, Lnginet will be saved in the next step and will be passed to InternetConnect
The value of the handle to the function.
2, by calling the InternetConnect function to connect with the host. VB specific call to this function declaration is:
Private Declare Function internetconnect Lib "Wininet.dll" Alias "Internetconnecta" _
(ByVal hinternetsession as Long, ByVal sServerName as String, _
ByVal Nserverport as Integer, ByVal sUserName as String, _
ByVal Spassword as String, ByVal Lservice as Long, _

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.