Create an FTP component with VB (Put)

Source: Internet
Author: User
Tags ftp connect
The basic steps to create are:


1, call the InternetOpen function to set up the environment.

2, call the InternetConnect function to connect the host.

3, call the FtpPutFile function to get the file.

4, with the InternetCloseHandle function to close the 1th, 2-step handle.



When using FtpGetFile, it looks exactly the same as the steps above. The only difference, in fact, is to call FtpPutFile in step 3rd. VB specific call to this function declaration is:


Private Declare Function ftpputfile Lib "Wininet.dll" Alias "Ftpputfilea" _

(ByVal hftpsession as Long, ByVal Lpszlocalfile as String, _

ByVal Lpszremotefile as String, ByVal dwflags as Long, _

ByVal Dwcontext as Long) as Boolean



The first parameter hftpsession is the handle value returned by the InternetConnect call.

Lpsznewfile and Lpszremotefile are the file names on the local machine and the names of the files that will be created on the remote host.

The parameter dwflags is specified as 1 o'clock, the file is transferred in ASCII (Class A transmission method), and the specified 2 is a binary transfer file (1 class transmission method). Since DIRMAP.TXT is an ASCII text file, we pass the value 1.

Finally, when the callback signal is used, lcontext is used to identify the relationship between the applications. Because the callback signal is not used in our example, the value is 0.

The following is to get the DIRMAP.TXT file and C:\DIRMAP it. TXT call.

BLNRC = FtpPutFile (Lnginetconn, "C::\dirmap.txt", "Dirmap.txt", 1, 0)

If the function call succeeds, the BLNRC is True, and false instead.

As you can see, putting files on an FTP server is as easy as getting files from an FTP server. It is important to note that anonymous users do not have permission to create files on the FTP server. So make sure that the user account that you use to connect to the FTP server has permission to create files. Otherwise, the FtpPutFile function call returns FALSE, stating that the put failed.



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.