VB 文件传输函数(版本自动更新用 MY_FILE_FTP.cls)

Wesley13
• 阅读 946
Option Explicit

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

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, _
ByVal lFlags As Long, ByVal lContext As Long) As Long

Private 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 Long) As Boolean

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

Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" _
  (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean

Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _
  (ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Private 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) As Long

Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
(ByVal hFind As Long, lpvFndData As WIN32_FIND_DATA) As Long

Const INTERNET_OPEN_TYPE_PRECONFIG = 0

Private Type FILETIME
  dwLowDateTime As Long
  dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
   dwFilAttributes 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 * 260
   cAlternate As String * 14
End Type

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
        "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
     lStructSize As Long
     hwndOwner As Long
     hInstance As Long
     lpstrFilter As String
     lpstrCustomFilter As String
     nMaxCustFilter As Long
     nFilterIndex As Long
     lpstrFile As String
     nMaxFile As Long
     lpstrFileTitle As String
     nMaxFileTitle As Long
     lpstrInitialDir As String
     lpstrTitle As String
     flags As Long
     nFileOffset As Integer
     nFileExtension As Integer
     lpstrDefExt As String
     lCustData As Long
     lpfnHook As Long
     lpTemplateName As String
End Type

Public Function F_ftp_getfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String
    F_ftp_getfile = ""
    Dim lnginet
    Dim lnginetconn
    Dim blnRC
    Dim lpFileData As WIN32_FIND_DATA
    lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
    If lnginet Then
       lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0)
      If lnginetconn Then
           blnRC = FtpGetFile(lnginetconn, remotefile, ftpfile, 0, 0, 1, 0)
          If blnRC Then
             F_ftp_getfile = "1"
          Else
             F_ftp_getfile = "0"
          End If
       Else
             F_ftp_getfile = "0"
      End If
    Else
    End If
    InternetCloseHandle lnginetconn
    InternetCloseHandle lnginet
End Function

Public Function F_ftp_putfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String
    F_ftp_putfile = ""
    Dim lnginet
    Dim lnginetconn
    Dim blnRC
    Dim aa As Long
    Dim lpFileData As WIN32_FIND_DATA
    lpFileData.cFileName = String(260, 0)
    lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
    If lnginet Then
        lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0)
        If lnginetconn Then
            aa = FtpFindFirstFile(lnginetconn, remotefile, lpFileData, 0, 0)
            blnRC = FtpPutFile(lnginetconn, ftpfile, remotefile, 1, 0)
            If blnRC Then
                F_ftp_putfile = "1"
            Else
                F_ftp_putfile = "0"
            End If
        Else
            F_ftp_putfile = "0"
        End If
    Else
    End If
    InternetCloseHandle lnginetconn
    InternetCloseHandle lnginet
End Function


Public Function F_ftp_getMfile(hostip As Variant, username As Variant, PASSWORD As Variant, remotefile As Variant, ftpfile As Variant) As String
    F_ftp_getMfile = ""
    Dim lnginet
    Dim lnginetconn
    Dim blnRC
    lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)
    If lnginet Then
       lnginetconn = InternetConnect(lnginet, hostip, 0, username, PASSWORD, 1, 0, 0)
      If lnginetconn Then
           blnRC = FtpGetFile(lnginetconn, remotefile, ftpfile, 0, 0, 1, 0)
          If blnRC Then
             F_ftp_getMfile = "1"
          Else
             F_ftp_getMfile = "0"
          End If
       Else
             F_ftp_getMfile = "0"
      End If
    Else
    End If
    InternetCloseHandle lnginetconn
    InternetCloseHandle lnginet
End Function
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
4个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这