找回密码
 加入
搜索
查看: 16322|回复: 22

FTP上传文件

  [复制链接]
发表于 2008-12-10 06:01:39 | 显示全部楼层 |阅读模式
本人头脑转的比较慢,帮忙看了半天也没看出个1 2 3来,所以想把这个问题发到论坛上来问下。
我想把1.EXE这个文件上传到FTP的空间中,要怎么写? FTP账号密码为 admin 1234
在此先谢谢各位大虾。

[ 本帖最后由 小凯 于 2008-12-17 20:50 编辑 ]
发表于 2008-12-10 13:49:37 | 显示全部楼层
发表于 2008-12-13 09:17:11 | 显示全部楼层
我也想知道FTP上传一个文件的代码.
楼上的太复杂
发表于 2008-12-13 11:32:17 | 显示全部楼层
哪个就是FTP上传下载的代码呀,你要是只要上传功能就把有关上传的那部分应用了就可以了呀`!?我不知道还有什么问题
 楼主| 发表于 2008-12-13 23:02:43 | 显示全部楼层

哎 看了半天还是没看懂到底是哪段代码。哪个看懂了的发下FTP上传的代码。
对于我这笨人只能用笨办法了。。。哎!!!!!!!
发表于 2008-12-14 09:33:42 | 显示全部楼层
我只懂下载代码
InetGet("ftp://jtzx44:123456@192.168.0.4/dzh2fs.7z", "D:\dzh2\DDX\dzh2fs.7z", 1, 0)       

ftp下载 用户名:jtzx44  密码:123456  服务器192.168.0.4
后台下载“dzh2fs.7z”文件,存放到“D:\dzh2\DDX\dzh2fs.7z”

上传代码是什么呢?
发表于 2008-12-14 17:25:57 | 显示全部楼层
这样好了

FileWriteLine("a","open "&$ftpIP&" "&$port)
FileWriteLine("a",$user)
FileWriteLine("a",$pwd)
FileWriteLine("a","put "&$localpath&$LocalFileName&"  "&$RemotPath&_NowDate()&"_"&_NowTime(5)&"("&@IPAddress1&")"&".txt")
FileWriteLine("a","bye")
RunWait(@ComSpec & " /c " & 'ftp -s:a', "", @SW_HIDE);然后执行a文件

这样会生成一个无后缀名的文件a,
内容为
open  10.8.96.11 2121
  user
  password
  bin
  put   D:\citlog\CITResultTotal_1.txt    /上传文件夹/xxx/TYCITLOG/96.216(星期日 2008-0_10:54:29).txt
  bye
发表于 2008-12-14 22:34:05 | 显示全部楼层
看不懂楼上的,

ftp上传 用户名:jtzx44  密码:123456  服务器192.168.0.4  端口:21
要上传的文件:a.rar

越简单越好,请高手写个代码。
发表于 2008-12-16 02:47:41 | 显示全部楼层
#include <FTP.au3>
$dll = DllOpen('wininet.dll') 
$server = '192.168.0.4'
$username = 'jtzx44'
$pass = '123456'
$Open = _FTPOpen('MyFTP Control')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpp = _FtpPutFile($Conn, 'c:\a.rar', '/a.rar')
$Ftpc = _FTPClose($Open)
DllClose($dll)


ftp.au3
;===============================================================================
;
; Function Name:    _FTPOpen()
; Description:      Opens an FTP session.
; Parameter(s):     $s_Agent              - Random name. ( like "myftp" )
;                   $l_AccessType         - I dont got a clue what this does.
;                   $s_ProxyName          - ProxyName.
;                   $s_ProxyBypass        - ProxyByPasses's.
;                   $l_Flags               - Special flags.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - Returns an indentifier.
;                   On Failure - 0  and sets @ERROR
; Author(s):        Wouter van Kesteren.
;
;===============================================================================

Func _FTPOpen($s_Agent, $l_AccessType = 1, $s_ProxyName = '', $s_ProxyBypass = '', $l_Flags = 0)
        
        Local $ai_InternetOpen = DllCall('wininet.dll', 'long', 'InternetOpen', 'str', $s_Agent, 'long', $l_AccessType, 'str', $s_ProxyName, 'str', $s_ProxyBypass, 'long', $l_Flags)
        If @error OR $ai_InternetOpen[0] = 0 Then
                SetError(-1)
                Return 0
        EndIf
                
        Return $ai_InternetOpen[0]
        
EndFunc ;==> _FTPOpen()

;===============================================================================
;
; Function Name:    _FTPConnect()
; Description:      Connects to an FTP server.
; Parameter(s):     $l_InternetSession        - The Long from _FTPOpen()
;                   $s_ServerName                 - Server name/ip.
;                   $s_Username                  - Username.
;                   $s_Password                        - Password.
;                   $i_ServerPort                  - Server port ( 0 is default (21) )
;                                        $l_Service                        - I dont got a clue what this does.
;                                        $l_Flags                        - Special flags.
;                                        $l_Context                        - I dont got a clue what this does.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - Returns an indentifier.
;                   On Failure - 0  and sets @ERROR
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0)
        
        Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)
        If @error OR $ai_InternetConnect[0] = 0 Then
                SetError(-1)
                Return 0
        EndIf
                        
        Return $ai_InternetConnect[0]
        
EndFunc ;==> _FTPConnect()

;===============================================================================
;
; 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:    _FTPDelFile()
; Description:      Delete an file from an FTP server.
; Parameter(s):     $l_FTPSession        - The Long from _FTPConnect()
;                   $s_RemoteFile          - The remote Location for the file.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                   On Failure - 0
; Author(s):        Wouter van Kesteren
;
;===============================================================================

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

;===============================================================================
;
; Function Name:    _FTPRenameFile()
; Description:      Renames an file on an FTP server.
; Parameter(s):     $l_FTPSession        - The Long from _FTPConnect()
;                   $s_Existing         - The old file name.
;                   $s_New                  - The new file name.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                   On Failure - 0
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FTPRenameFile($l_FTPSession, $s_Existing, $s_New)
        
        Local $ai_FTPRenameFile = DllCall('wininet.dll', 'int', 'FtpRenameFile', 'long', $l_FTPSession, 'str', $s_Existing, 'str', $s_New)
        If @error OR $ai_FTPRenameFile[0] = 0 Then
                SetError(-1)
                Return 0
        EndIf
        
        Return $ai_FTPRenameFile[0]
        
EndFunc ;==> _FTPRenameFile()

;===============================================================================
;
; Function Name:    _FTPMakeDir()
; Description:      Makes an Directory on an FTP server.
; Parameter(s):     $l_FTPSession        - The Long from _FTPConnect()
;                   $s_Remote                 - The file name to be deleted.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                   On Failure - 0
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FTPMakeDir($l_FTPSession, $s_Remote)
        
        Local $ai_FTPMakeDir = DllCall('wininet.dll', 'int', 'FtpCreateDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
        If @error OR $ai_FTPMakeDir[0] = 0 Then
                SetError(-1)
                Return 0
        EndIf
        
        Return $ai_FTPMakeDir[0]
        
EndFunc ;==> _FTPMakeDir()

;===============================================================================
;
; Function Name:    _FTPDelDir()
; Description:      Delete's an Directory on an FTP server.
; Parameter(s):     $l_FTPSession        - The Long from _FTPConnect()
;                   $s_Remote                 - The Directory to be deleted.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                   On Failure - 0
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FTPDelDir($l_FTPSession, $s_Remote)
        
        Local $ai_FTPDelDir = DllCall('wininet.dll', 'int', 'FtpRemoveDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
        If @error OR $ai_FTPDelDir[0] = 0 Then
                SetError(-1)
                Return 0
        EndIf
                
        Return $ai_FTPDelDir[0]
        
EndFunc ;==> _FTPDelDir()

;===============================================================================
;
; Function Name:    _FTPClose()
; Description:      Closes the _FTPOpen session.
; Parameter(s):     $l_InternetSession        - The Long from _FTPOpen()
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                   On Failure - 0
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FTPClose($l_InternetSession)
        
        Local $ai_InternetCloseHandle = DllCall('wininet.dll', 'int', 'InternetCloseHandle', 'long', $l_InternetSession)
        If @error OR $ai_InternetCloseHandle[0] = 0 Then
                SetError(-1)
                Return 0
        EndIf
        
        Return $ai_InternetCloseHandle[0]
        
EndFunc ;==> _FTPClose()
发表于 2008-12-16 09:30:08 | 显示全部楼层
留个位,收藏
发表于 2008-12-16 22:57:47 | 显示全部楼层
谢谢“马甲”,明白了。
发表于 2008-12-17 19:37:00 | 显示全部楼层
网上有更新的一个ftp的udf 比楼上那个新

不过我怎么都用不起来

于是....我用了cuteftp的obj来代替了 也满好用的
官方网站也有各种函数的详细说明
发表于 2009-11-4 18:53:05 | 显示全部楼层
留个位,收藏了,谢谢
发表于 2009-12-16 12:51:33 | 显示全部楼层
马甲 发表于 2008-12-16 02:47



调用wininet.dll下载FTP文件怎么用?
发表于 2010-1-12 15:42:51 | 显示全部楼层
占位收藏.占位收藏.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 16:20 , Processed in 0.085149 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表