Web page Upload files by self-writty FTP components

xiaoxiao2021-03-06  65

Recently, because of a video on-demand system, there is no way to achieve such a large transmission data of more than 300M, and think about it. It is better to use FTP !!! Think: A Web section 1 first put the web Page Get the file name 2 Web to be uploaded to the local file name (absolute path) to the client component 3 Web script control components to the Client Component 3 Web Script Control Components to the Client Component 3 Web Script Control Components Starting Data 4 Finally, it is determined whether to transmit success 2 component section 1 Establish Internet connection 2 Connection FTP server 3 Get a local file name (absolute path) 4 Returns the remote upcoming file name 5 Transfer data 6 Judging whether the transmission is successful, return status

WEB page Get a local file component Returns Remote File Name Component Transfer Data Back

In this case, the VB6.0 WIN2000 IIS5.0 Serv-U 5.0 is down-regulated, and an ActiveX DLL project is established. Change the project name ftpconn. Change the class name: clsputfile 4, join an empty module to the project In this module mainly declares the functions that need to be used, don't explain this, the code is as follows: Option Explicit

Declare Function GetProcessHeap Lib "kernel32" () As LongDeclare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As LongDeclare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpmem as any) As longpublic constheap_zero_memory = & h8public const heap_generate_exceptions = & h4

Declare Sub CopyMemory1 Lib "kernel32" Alias ​​"RtlMoveMemory" (_ hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long) Declare Sub CopyMemory2 Lib "kernel32" Alias ​​"RtlMoveMemory" (_ hpvDest As Long, hpvSource As Any, ByVal cbCopy As long

Public Const MAX_PATH = 260Public Const NO_ERROR = 0Public Const FILE_ATTRIBUTE_READONLY = & H1Public Const FILE_ATTRIBUTE_HIDDEN = & H2Public Const FILE_ATTRIBUTE_SYSTEM = & H4Public Const FILE_ATTRIBUTE_DIRECTORY = & H10Public Const FILE_ATTRIBUTE_ARCHIVE = & H20Public Const FILE_ATTRIBUTE_NORMAL = & H80Public Const FILE_ATTRIBUTE_TEMPORARY = & H100Public Const FILE_ATTRIBUTE_COMPRESSED = & H800Public Const FILE_ATTRIBUTE_OFFLINE = & H1000Type FILETIME dwLowDateTime As Long dwHighDateTime As lucked type

Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14End Type

Public const error_no_more_files = 18

Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias ​​"InternetFindNextFileA" _ (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias ​​"FtpFindFirstFileA" _ (ByVal hFtpSession As Long, ByVal lpszSearchFile As string, _ lpfindfiledata as win32_find_data, byval dwflags as long, byval dwcontent as long

Public Declare Function FtpGetFile Lib "wininet.dll" Alias ​​"FtpGetFileA" _ (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _ ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Long, _ ByVal dwFlags As Long, ByVal dwContext As boolean

Public 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

Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias ​​"FtpSetCurrentDirectoryA" _ (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean 'Initializes an application's use of the Win32 Internet functionsPublic Declare Function InternetOpen Lib "wininet.dll" Alias ​​"InternetOpenA "_ (Byval Sagent As String, Byval Sproxyname As String, _Byval SproxybyPass As String, Byval LFLAGS AS Long) As long

'User agent constant.public const scuseragent = "VB Wininet"

'Use registry access settings.Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0Public Const INTERNET_OPEN_TYPE_DIRECT = 1Public Const INTERNET_OPEN_TYPE_PROXY = 3Public Const INTERNET_INVALID_PORT_NUMBER = 0

Public const ftp_transfer_type_ascii = & h1public const ftp_transfer_type_binary = & h1public const internet_flag_passive = & h8000000

'Opens a HTTP session for a given site.Public 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, _ByVal lFlags As Long, ByVal lContext As Long) As Long Public Const ERROR_INTERNET_EXTENDED_ERROR = 12003Public Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias ​​"InternetGetLastResponseInfoA" (_ lpdwError As Long, _ ByVal lpszBuffer As String, _ lpdwBufferLength As Long) As Boolean 'Number of the TCP / IP port on the server to connect to.Public Const INTERNET_DEFAULT_FTP_PORT = 21Public Const INTERNET_DEFAULT_GOPHER_PORT = 70Public Const INTERNET_DEFAULT_HTTP_PORT = 80Public Const INTERNET_DEFAULT_HTTPS_PORT = 443Public Const INTERNET_DEFAULT_SOCKS_PORT = 1080

Public const interface_option_connect_timeout = 2public const interface_option_receive_timeout = 6PUBLIC Const Internet_Option_send_timeout = 5

Public const interface_option_username = 28public const interface_option_password = 29public const interface_option_proxy_username = 43public const interface_option_proxy_password = 44

'Type of service to access.public const interface_service_ftp = 1public const interface_service_gopher = 2PUBLIC Const Internet_Service_HTTP = 3

'Opens an HTTP request handle.Public Declare Function HttpOpenRequest Lib "wininet.dll" Alias ​​"HttpOpenRequestA" _ (ByVal hHttpSession As Long, ByVal sVerb As String, ByVal sObjectName As String, ByVal sVersion As String, _ByVal sReferer As String, ByVal something As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long 'Brings the data across the wire even if it locally cached.Public Const INTERNET_FLAG_RELOAD = & H80000000Public Const INTERNET_FLAG_KEEP_CONNECTION = & H400000Public Const INTERNET_FLAG_MULTIPART = & H200000

Public const generic_read = & h80000000public const generic_write = & h40000000

'Sends the specified request to the HTTP server.Public Declare Function HttpSendRequest Lib "wininet.dll" Alias ​​"HttpSendRequestA" (ByVal _hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal sOptional As _String, ByVal lOptionalLength As Long) As integer

'Queries for information about an HTTP request.Public Declare Function HttpQueryInfo Lib "wininet.dll" Alias ​​"HttpQueryInfoA" _ (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, _ByRef lBufferLength As Long, ByRef lIndex As Long) As integer

'The possible values ​​for the lInfoLevel parameter include: Public Const HTTP_QUERY_CONTENT_TYPE = 1Public Const HTTP_QUERY_CONTENT_LENGTH = 5Public Const HTTP_QUERY_EXPIRES = 10Public Const HTTP_QUERY_LAST_MODIFIED = 11Public Const HTTP_QUERY_PRAGMA = 17Public Const HTTP_QUERY_VERSION = 18Public Const HTTP_QUERY_STATUS_CODE = 19Public Const HTTP_QUERY_STATUS_TEXT = 20Public Const HTTP_QUERY_RAW_HEADERS = 21Public Const HTTP_QUERY_RAW_HEADERS_CRLF = 22Public Const HTTP_QUERY_FORWARDED = 30Public Const HTTP_QUERY_SERVER = 37Public Const HTTP_QUERY_USER_AGENT = 39Public Const HTTP_QUERY_SET_COOKIE = 43Public Const HTTP_QUERY_REQUEST_METHOD = 45Public Const HTTP_STATUS_DENIED = 401Public Const HTTP_STATUS_PROXY_AUTH_REQ = 407 'Add this flag to the about flags to get request header.Public Const HTTP_QUERY_FLAG_REQUEST_HEADERS = & H80000000Public Const HTTP_QUERY_FLAG_NUMBER = & H20000000 'Reads Data from a Handle Opened by The HttpopenRequest Function.public Declare Function InternetReadFile LIB "Wininet.dll" _ (Byval Hfile As stay, Byval Sbuffer As String, BYVAL LNUMBYTESTOREAD As long, _lnumberofbytesread as long) AS Integer

Public Declare Function InternetWriteFile LIB "Wininet.dll" _ (Byval Hfile As Long, BYVAL SBUFFER AS STRING, _ BYVAL LNUMBEROFBYTESTOREAD As Long, _ lunumberofbytesread as long) AS Integer

Public Declare Function FtpOpenFile Lib "wininet.dll" Alias ​​_ "FtpOpenFileA" (ByVal hFtpSession As Long, _ ByVal sFileName As String, ByVal lAccess As Long, _ ByVal lFlags As Long, ByVal lContext As Long) As LongPublic Declare Function FtpDeleteFile Lib " wininet.dll "_ Alias" FtpDeleteFileA "(ByVal hFtpSession As Long, _ ByVal lpszFileName As String) As BooleanPublic Declare Function InternetSetOption Lib" wininet.dll "Alias" InternetSetOptionA "_ (ByVal hInternet As Long, ByVal lOption As Long, ByRef sBuffer As Any, ByVal lBufferLength As Long) As IntegerPublic Declare Function InternetSetOptionStr Lib "wininet.dll" Alias ​​"InternetSetOptionA" _ (ByVal hInternet As Long, ByVal lOption As Long, ByVal sBuffer As String, ByVal lBufferLength As Long) As Integer 'Closes a SINGLE Internet Handle OR A Subtree Of Internet Handles.public Declare Function InternetCloseHandle Lib "WinInet.dll" _ (Byval Hinet As long) AS Integer

'Queries an Internet option on the specified handlePublic Declare Function InternetQueryOption Lib "wininet.dll" Alias ​​"InternetQueryOptionA" _ (ByVal hInternet As Long, ByVal lOption As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long) As Integer

'Returns the version Number of wininet.dll.public const interface_option_version = 40

'Contains the version number of the DLL that contains the Windows Internet' functions (Wininet.dll). This structure is used when passing the 'INTERNET_OPTION_VERSION flag to the InternetQueryOption function.Public Type tWinInetDLLVersion lMajorVersion As Long lMinorVersion As LongEnd Type

'Adds one or more HTTP request headers to the HTTP request handle.Public Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias ​​"HttpAddRequestHeadersA" _ (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, _ByVal lModifiers As Long) AS Integer 'Flags To Modify The Semantics of this function. Can be becombination of these Values:

'Adds the header only if it does not already exist; otherwise, an error is returned.public const http_addreq_flag_add_if_new = & h10000000

'Adds the header if it does not exist. Ready with replace.public const http_addreq_flag_add = & h20000000

'Replaces or Removes a header. If the header value is es Empty and the header is found,' it is remoded. If not empty, the header value is replacedpublic const http_addreq_flag_replace = & h80000000

Fifth, the class code input, as follows: Option ExplicitDim bActiveSession As BooleanDim hOpen As LongDim hConnection As LongDim scUserAgent As StringDim strServer As StringDim strUser As StringDim strPassword As StringDim nFlag As LongDim bRet As BooleanDim szFileLocal As StringDim szFileRemote As StringDim dwType As Integer

Public Function PUTFILE () As BooleanOn Error Resume NexthOpen = InternetOpen (scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0) hConnection = InternetConnect (hOpen, strServer, INTERNET_INVALID_PORT_NUMBER, strUser, strPassword, INTERNET_SERVICE_FTP, nFlag, 0) bRet = FtpPutFile (hConnection, szFileLocal , SZFileRemote, _ DewType, 0) Call CloseConnputFile = Bretend Function

Sub closeconn () if hconnection <> 0 Then InternetCloseHandle Hconnection Hconnection = 0nd Sub

Function getRemoteName (filename) Dim arrName () As String arrName = Split (filename, ".") Randomize getRemoteName = Date & CInt (Rnd * 1000) & "." & ArrName (UBound (arrName)) End FunctionPrivate Sub Class_Initialize () scUserAgent = "My FTP" strServer = "www.XXX.cn" strUser = "Username" strPassword = "Password" nFlag = INTERNET_FLAG_PASSIVE szFileLocal = "DefultLocalFileName" szFileRemote = "DefultRemoteFileName" dwType = 1End Sub

Public property Get ConnServer () AS VARIANT ConnServer = strserverend Property

Public Property Let ConnServer (Byval VNewValue As Variant) strserver = vnewvalueend property

Public property Get Connuser () As Variant Connuser = STRUSEREND PROPERTY

Public Property Let Connuser (Byval VNewValue As Variant) Struser = VNewValueEnd Property

Public property get connpassword () as variant connpassword = strpasswordnd property

Public property let connpassword (byval vnewvalue as variant) strpassword = vnewvalueend property

Public Property Let LocalFileName (Byval VNewValue As Variant) SZFILELOCAL = VNewValue SzfileRemote = GetRemotename (VNewValue) End Property

Public property Get RemoteFileName () AS VARIANT RemoteFileName = SZFILEMOTEEND PROPERTY

6. Generate DLL seven, packaging into "Internet ActiveX installation package" using VB6 packages, this is, after the VB package, will give an example of HTML file eight, establish an HTML file ftpconn .Cab </ title> </ head> <body> <object id = "clsputfile" classid = "CLSID: D9BACC8F-0A99-46DA-ADA3-F1C25A48AA78" CodeBase = "ftpconn.cab # Version = 1, 0, 0, 0 "> </ Object> <input type =" file "name =" filename "> <button οnclick =" go ()> go ~! </ Button> <script language = "javascript"> <! - by NEWROCKY 2004-12-7 QQ: 1936234 Function Go () {if (filename.value! = ') {Clsputfile.localFilename = filename.value; Alert (clsputfile.remoteFileName); // View Remote File Name IF (Clsputfile. Putfile ()) // Start the transfer file, if returned to True, it is successful, and the reverse failed {Alert ('uploaded file success!');} Else {Alert ('upload file failed!')}} Else {Alert ('Please select The file you want to upload ');}} // -> </ script> </ body> </ html> ok ~!</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-83685.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="83685" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.035</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'NISJAKtR_2Bixdd8EXNwe2Iwo9K_2BWfu2l1AUT0EboThVS883qKS2BOkRLorEcuClZueLSo8QvAAzTJPkMK'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>