Jump to content

FTP.au3


w0uter
 Share

Recommended Posts

I tried this, but won´t wrk too. :D

Func _FTPOpenFile($l_FTPSession, $s_FilePath, $access, $dwflags, $l_Context = 0)
    If $access = 1 Then
        $dwAccess = 0x40000000
    Else
        $dwAccess = 0x80000000
    EndIf   
    
    
        
    Local $ai_FTPOpenFile = DllCall('wininet.dll', 'none', 'FtpOpenFile', 'long', $l_FTPSession, 'str', $s_FilePath, 'int', $dwAccess, 'int', $dwFlags, 'long', $l_Context)
    If @error OR $ai_FTPOpenFile[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
        
    Return $ai_FTPOpenFile[0]
    
EndFunc
Link to comment
Share on other sites

  • Replies 283
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 1 month later...

This method get files from remote ftp server.

I tested it and its works for me.

;===============================================================================
;
; Function Name:    _FTPGetFile()
; Description:    Get file from a 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_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)

    Local $ai_FTPGetFile = DllCall('wininet.dll', 'int', 'FtpGetFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, '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()
Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Hello,

iam new here and want to write the following script in autoit

I want to create a directory on my FTP server with CHMOD 777, that any user can push files there.

I found to use this code:

;===============================================================================
;
; 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()

But this script only chnages the permissions to 745.

Is there a change, and can somebody help me to get the permissions to 777.

Would be great!

Thanks,

Markus

Link to comment
Share on other sites

I've looked through the forums and I have not seen anything about this so I hope that I'm not asking a question that already has an answer. I am a firm believer in RTFM. :P

When I want to delete a folder from a remote FTP server, does the folder need to be empty first? Or can I just delete the folder and it will take out all of the files automatically?

Endgame

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 2 weeks later...

Is there a way to check the free disk space still available on an ftp site? Or, space currently being used up?

I work for a company that periodically needs to poll ftp sites, get files, we process them, then put files back into their site. Occasionally, we run into the problem where their ftp site has run out of disk space.

I was hoping to make a script to check for disk space still available and run it a few days before I know I'll be uploading files onto their site. That way I could give them a day or 2 heads up that they need somebody on their end to clear up some space for the incoming data.

Link to comment
Share on other sites

I am trying to use the _FTPGetFileSize function to compare the size of the file after it was ftp'ed to before it was ftp'ed. on the first pass through the while loop the file will be transmitted and I get the size just fine, on the second pass it will error out on the _FTPputfile command as if the connection was closed.

Hi jerran,

I am having similar problems,

after getting the filesize by _FTPGetFileSize of an existing file I cant upload anymore by _FtpPutFile.

As long I do "_FTPGetFileSize" - tests to non-existings files "_FtpPutFile" works fine - after the first positive occurence of "_FTPGetFileSize" it doesnt work anymore.

Link to comment
Share on other sites

I'd be interesting for the FTPOpenFile but it doesn't work.. I tried several things but nothing works.

Edited by Joke758

[u]My Programs:[/u]Word Search Creator - Make your own Word SearchShortHand - Hide a secret message in a jpg fileHex Editor - Edit your Binary fileIncrease file size - Increase the size of any filesArt Generator - A program that generate random picture[u]My Functions:[/u]16-Bits Hash - My Hash function similar to MD5Probabilities - My probabilities function (factorial, permuation, combination)_GetDate() - Convert a date to a day of the week_Base(), _Dec() - Convert a number in any base (bin, oct, hex, dec). Create your own!

Link to comment
Share on other sites

You have to close and reopen the connection for each file that you want to get the size of. they talk about it here under remarks.

FTPFileOpen

I found that something like this works...

$server = '192.168.0.3'

$username = 'xbox'

$pass = 'xbox'

For $i = 1 to $TransferList[0]

$Open = _FTPOpen('xbox')

$Conn = _FTPConnect($Open, $server, $username, $pass, 1)

$setdir = _FTPSetCurrentDir($Conn, '/F/Videos/')

$size = _FTPGetFileSize($Conn, $TransferList[$i])

MsgBox(0, '', $size & ' ' & $TransferList[$i])

$Ftpc = _FTPClose($Open)

Next

Edited by bchris01
Link to comment
Share on other sites

Hi All,

I needed a procedure to recursively get the contents of a remote directly, so here it is:

;===============================================================================
;
; Function Name:    _FTPGetFoldercontents
; Description:    Recursively retrieves the contents of a directory on an FTP server.
; Parameter(s):  $s_Server   - Server name/ip.
;                  $s_Username   - Username.
;                  $s_Password   - Password.
;                  $s_RemoteDir  - The directory on the server to retrieve.  End in "/"
;                  $s_LocalDir   - The Local directory to save to
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - None.  Byref variable $i_Count returns number of files (not
;                                      including directories) transferred.
;                  On Failure - None, exits with Msg.  Opportunity here for some improvement
; Author(s):        Walkabout 2006-10-18
;
;===============================================================================
Func _FTPGetFolderContents($s_Server, $s_UserName, $s_Password, $s_RemoteDir, $s_LocalDir, ByRef $i_Count)
    Local $h_Handle
    Local $DllRect
    Local $FileInfo[12]
    Local $Open
    Local $Conn
    Local $s_Filename
    
;Open the Connection.  This has to be done for each new level of recusion.
    $Open = _FTPOpen ('MyFTP Control')
    If @error Then Failed ("Open")
    $Conn = _FTPConnect ($Open, $s_Server, $s_UserName, $s_Password, 1)
    If @error Then Failed ("Connect")
    
;First File
    If Not FileExists($s_LocalDir) Then DirCreate($s_LocalDir)
    $FileInfo = _FtpFileFindFirst ($Conn, $s_RemoteDir & '*.*', $h_Handle, $DllRect)
    $error = @error
    If Not $FileInfo[0] Then Return
    $s_Filename = $FileInfo[10]
    
    ConsoleWrite($i_Count & " - " & $s_RemoteDir & $s_Filename & @LF)
    
    If $FileInfo[1] = 16 Then;Directory.  Recurse down one level
        If $s_Filename <> "." And $s_Filename <> ".." Then
            If Not FileExists($s_LocalDir & $s_Filename & "\") Then DirCreate($s_LocalDir & $s_Filename & "\")
            _FTPGetFolderContents($s_Server, $s_UserName, $s_Password, $s_RemoteDir & $s_Filename & "/", $s_LocalDir & $s_Filename & "\", $i_Count)
        EndIf
    Else; File.  Retrieve it
        $Result = _FTPGetFile ($Conn, $s_RemoteDir & $s_Filename, $s_LocalDir & $s_Filename)
        $i_Count += 1
    EndIf
    
;Subsequent Files
    While 1
        $FileInfo = _FtpFileFindNext ($h_Handle, $DllRect)
        If Not $FileInfo[0] Then Return
        $s_Filename = $FileInfo[10]
        
        ConsoleWrite($i_Count & " - " & $s_RemoteDir & $s_Filename & @LF)
        
        If $FileInfo[1] = 16 Then;Directory.  Recurse down one level
            If $s_Filename <> "." And $s_Filename <> ".." Then
                If Not FileExists($s_LocalDir & $s_Filename & "\") Then DirCreate($s_LocalDir & $s_Filename & "\")
                _FTPGetFolderContents($s_Server, $s_UserName, $s_Password, $s_RemoteDir & $s_Filename & "/", $s_LocalDir & $s_Filename & "\", $i_Count)
            EndIf
        Else; File.  Retrieve it
            $Result = _FTPGetFile ($Conn, $s_RemoteDir & $s_Filename, $s_LocalDir & $s_Filename)
            $i_Count += 1
        EndIf
    WEnd
    
EndFunc  ;==>_FTPGetFolderContents

and an example

#include <ftp.au3>

$server = 'ftp.myserver.com'
$username = 'ftpuser'
$pass = 'password'

Local $RemoteDir = '/wwwroot/'
Local $LocalDir = "C:\TempDir\"
Local $Count = 0
_FTPGetFolderContents($Server, $UserName, $Pass, $RemoteDir, $LocalDir,$Count)

msgbox(0,"Complete",$Count & " Records Processed")

I played around with the code a little, tidying it up before posting. As I can't test that my changes haven't broken it, let me know if you spot any issues.

Walkabout

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...

I needed a function it can download file from a ftp server.

The function "INETGET" can do it ,but when download file use "INETGET",it write the target file and write the internet TEMP file at on time too,so caused the computer slowly.

(谢谢)THX.

InetGet?? Did you read the first post of this thread???

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...