自己编写的一个函数,可以加入到ftp.au3中

本文介绍了一个使用AutoIt编写的FTP文件上传与下载脚本,包括_FTPPutFile和_FTPGetFile两个函数的实现。这些函数利用wininet.dll库进行操作,并详细解释了参数设置与返回值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

;===============================================================================
;
; Function Name:    _FTPPutFile()
; Description:      Puts an file on an FTP server.
; Parameter(s):     $l_FTPSession - The Long from _FTPConnect()
;                   $s_LocalFile  - The local file.
;                   $s_RemoteFile   - The remote Location for the file.
;                   $l_Flags  - Special flags.
;                   $l_Context   - I dont got a clue what this does.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                   On Failure - 0
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)

 Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
 If @error OR $ai_FTPPutFile[0] = 0 Then
  SetError(-1)
  Return 0
 EndIf
 
 Return $ai_FTPPutFile[0]
 
EndFunc ;==> _FTPPutFile()

;===============================================================================
;
; Function Name:    _FTPPutFile()
; Description:      Puts an file on an FTP server.
; Parameter(s):     $l_FTPSession - The Long from _FTPConnect()
;                   $s_LocalFile  - The local file.
;                   $s_RemoteFile   - The remote Location for the file.
;                   $l_Flags  - Special flags.
;                   $l_Context   - I dont got a clue what this does.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                   On Failure - 0
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FTPGetFile($l_FTPSession, $s_RemoteFile, $s_LocalFile, $s_Disabled = False, $s_FlagsAndAttributes = 0, $l_Flags = 0, $l_Context = 0)

 Local $ai_FTPGetFile = DllCall('wininet.dll', 'int', 'FtpGetFile', 'long', $l_FTPSession, 'str', $s_RemoteFile, 'str', $s_LocalFile,  "int", $s_Disabled , 'long', $l_Flags, 'long', $l_Context)
 If @error OR $ai_FTPGetFile[0] = 0 Then
  SetError(-1)
  Return 0
 EndIf
 
 Return $ai_FTPGetFile[0]
 
EndFunc ;==> _FTPGetFile()


;模仿_ftpputfile写的一个_ftpgetfile函数;
;参照了微软官方的msdn函数库
;msdn 查询方法为: msdn  函数名 通过g.cn搜索,可一次性找到所对应函数,在函数下方有函数所必需的dll文件的说明
;autoit脚本中没有bool变量
;$s_disabled在msdn中应该是BOOL fFailIfExists   参见FtpGetFile Function,在autoit v3中的表达方法如上,"int",$s_Disabled,用整型变量来表达了布尔变量值
;在参数声明的地方直接赋值,即可实现默认赋值方法

#include <FTP.au3>
$server = '127.0.0.1'
$username = ''
$pass = ''
$remoteFile = '/传输软件打包0904/Auto1hour(win2000).rar'
$localFile = 'D:/Lbghost/Auto1hour(win2000).rar'

$Open = _FTPOpen('MyFTP Control')
$Conn = _FTPConnect($Open, $server, $username, $pass)
If $Conn == 0 Then
 MsgBox(4096,"Wrong Test!","Can not open the FTP!",10)
 Exit
Else
    ToolTip(@CRLF & "    已经连接到FTP:" & $server & "    " & @CRLF, 800, 700, "", 1)
    Sleep(10000) 
EndIf  
$Ftpp = _FtpGetFile($Conn, $remoteFile, $localFile)
If $Ftpp == 0 Then
 MsgBox(4096,"Wrong Test!","There is an error occur!",10)
Else
 MsgBox(4096,"congratulate!","Your FTP Copy is successful!!!",10)
EndIf 
$Ftpc = _FTPClose($Open)
Exit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值