Jump to content

FTP.au3


w0uter
 Share

Recommended Posts

cant help mate.

my firewall is messing with vmware, so i cant access my ftp server ...

try removing the slash infront of the server path.

also what do the variables say.

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

  • Replies 283
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

basically, i see it connecting, it then just dis-connects and doesnt transfer any files.

i've tried this with 2 diff. ftp servers..

Blitzkrg, this sounds similar to the problem I was having with the script. Try using passive mode rather than the default active mode. You can do this either using the modified _FTPConnect function I posted (post #32) or by passing 0x08000000 to $l_flags as w0uter suggested in post #33.
Link to comment
Share on other sites

Blitzkrg, this sounds similar to the problem I was having with the script. Try using passive mode rather than the default active mode. You can do this either using the modified _FTPConnect function I posted (post #32) or by passing 0x08000000 to $l_flags as w0uter suggested in post #33.

nitro thanks for the reply.. i was hoping that did the trick. but it didnt.

i tried your new FTP submit app and it didnt work either..

i get connected and then disconnect..

but if i go to dos and just type ftp, everything works fine. i can login and have no issues.

Link to comment
Share on other sites

I used your FTP functions in an application and it's working flawlessly. Great work, thank you.

-Glen

The app I wrote allows the user to drag and drop a file onto the program icon, where it's zipped, encrypted, copied to a network share then ftp to another site. I elected to put the program in the users SEND TO folder so she merely need to right click on a file and choose SEND TO the ftp site. Works great for it's intended purpose (sending a secure monthly interface file to an out of network provider). If anyone is interested in the source, let me know. Many thanks to WOuter for his ftp functions.

Edited by gspino
Link to comment
Share on other sites

I would love to integrate a progress bar into this to display current upload status. Has this been covered elsewhere already?

I.E. - a way to pull total num of bytes sent so I can plug that into a progress meter loop.

Edited by jezzzzy
Link to comment
Share on other sites

  • 2 weeks later...

just to give you guys some update: im currently heavely(?) involved in schoolwork. ill think i will have a new updated version in about 3 weeks B)

Hi wouter,

Done a greate job...

I am using ur ftp script to upload files...

But when uploading huge mp3 files, the gui window gets hanged.

I cant minimize or maximize the window till the upload is over.

Is there a work around so that my gui window wont get effected while huge uploads...

Thanks once again for the script... :o

Moin.

Link to comment
Share on other sites

Hello all,

In over my head again! I have successfully used virtually every function in FTP.au3, but now find myself needing to get a list of the files on an FTP server for processing. I thought I'd get cute and try working with the wininet.dll myself, but quickly found myself lost. I believe the function I am looking for in the dll is FtpFindFirstFileA, but I could be wrong.

Any help would be greatly appreciated...

JPC B)

Link to comment
Share on other sites

  • 2 weeks later...

yup. and dont forget InternetFindNextFile (or something like that)

Hi w0uter,

I´m looking for the new FTP functions like InternetFindNextFile .

I´ve try it by myself, but I have the Problem to catch the returend Data from the DLL funktion call.

Please take a look at my code and correct it if you see any problems.

~ Declare Sub FtpFindFirstFileA Lib "wininet.dll" ( _
;~           ByRef hConnect As Long, _
;~           ByVal lpszSearchFile As String, _
;~           ByRef lpFindFileData As WIN32_FIND_DATA, _
;~           ByVal dwFlags As Long, _
;~           ByRef dwContext As Long)


;===============================================================================
;
; Function Name:    _FtpFindFirstFile()
; Description:    Find an file from an FTP server.
; Parameter(s):  $l_FTPSession  - The Long from _FTPConnect()
;                  $s_SearchFile      - The remote Location for the file.
;                  $s_FindFileData - Found file.
;                   $s_FlagsAndAttributes   
;                  $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):        wolkenloser
;
;===============================================================================


dim $s_FindFileData
dim $FtpFindFirstFile

Func _FtpFindFirstFile($l_FTPSession, $SearchFile, $l_Flags = 2, $l_Context = 0)

        ;Local $ai_FTPGetFile = DllCall('wininet.dll', 'int', 'FtpGetFile',  'long', $l_FTPSession, 'str', $s_RemoteFile, 'str', $s_NewLocalFile, 'long', $l_Fail, 'long', $l_Attributes, 'long', $l_Flags, 'long', $l_Context)
    Local $ai_FtpFindFirstFile = DllCall('wininet.dll','str', $FtpFindFirstFile, 'long', $l_FTPSession, 'str', $SearchFile, 'long' $l_Flags, 'long', $l_Context)
    If @error OR $ai_FtpFindFirstFile[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    Return $ai_FtpFindFirstFile[0]
    
EndFunc;==> _FtpFindFirstFile()
Link to comment
Share on other sites

here is what i had, it doesnt work. (based on the fact that the new version will have a different return layout)

but it gives you and idea how to do it.

(btw you should start using msdn since it gives more info: http://msdn.microsoft.com/library/default....ndfirstfile.asp B))

#region _FtpFindFirstFile

;===============================================================================
;
; Function Name:    _FtpFindFirstFile()
;
; Description:    Closes the _FtpOpen session.
;
; Parameter(s):  $l_FtpSession  - The Array from _FtpOpen()
;                  $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 - An array (see notes.)
;                  On Failure - 0
;
; Author(s):        Wouter van Kesteren
;
;===============================================================================

Func _FtpFindFirstFile($l_FtpSession, $s_RemoteFile = '', $l_Flags = 0x80000000, $l_Context = 0)
    
    $l_FtpSession = $l_FtpSession[1]
    
    Local $v_Struct = DllStructCreate('dword;dword[2];dword[2];dword[2];dword;dword;dword;dword;char[260];char[14]')
    
    Local $ai_FtpFindFirstFile = DllCall('wininet.dll', 'int', 'FtpFindFirstFile', 'long', $l_FtpSession, 'str', $s_RemoteFile, 'ptr', DllStructGetPtr($v_Struct), 'long', $l_Flags, 'long', $l_Context)
    If @error Or $ai_FtpFindFirstFile[0] = 0 Then
        SetError(1)
        Return 0
    EndIf
    
    Local $av_R[14]
    
    $av_R[0] = DllStructGetData($v_Struct, 1)
    
    $av_R[1] = DllStructGetData($v_Struct, 2, 1)
    $av_R[2] = DllStructGetData($v_Struct, 2, 2)
    $av_R[3] = DllStructGetData($v_Struct, 3, 1)
    $av_R[4] = DllStructGetData($v_Struct, 3, 2)
    $av_R[5] = DllStructGetData($v_Struct, 4, 1)
    $av_R[6] = DllStructGetData($v_Struct, 4, 2)
    
    For $i = 7 to 12
        $av_R[$i] = DllStructGetData($v_Struct, $i)
    Next
    
    DllStructDelete($v_Struct)
    
    $av_R[13] = $ai_FtpFindFirstFile[0]
    
    Return $av_R
    
    
EndFunc;==> _FtpFindFirstFile()

#endregion

#region _FtpFindNextFile

Func _FtpFindNextFile($h_Find)

    Local $v_Struct = DllStructCreate('dword;dword[2];dword[2];dword[2];dword;dword;dword;dword;char[260];char[14]')

    $av_InternetFindNextFile = DllCall('wininet.dll', 'int', 'InternetFindNextFile', 'long', $h_Find, 'ptr', DllStructGetPtr($v_Struct))
    If @error Or $av_InternetFindNextFile[0] = 0 Then
        SetError(1)
        Return 0
    EndIf

    $av_InternetFindNextFile = DllStructGetData($v_Struct, 8)
    DllStructDelete($v_Struct)

    return $av_InternetFindNextFile

EndFunc

#endregion
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

  • 4 weeks later...

Great job with FTP.au3. This really is the kind of script I hope to put up in a few months after really getting into the guts of the OS. (also, a mkdir variable may be incorrectly described in the comments)

Problem:

I notice with the old (ugly) version, you deal with the wildcard. I've tried using a wildcard with the new version but it fails on the upload. I simply change the filenames from *.jpg to actualfile.jpg and it works. Any ideas on this? I really don't want to put in an array for filenames. Anway, a mod to this script (or ftp.au3 if the problem is there) to make the wildcard work would be much appreciated.

#include <FTP.au3>
#Include <date.au3>

;Sweeps all jpg's from a folder into a new subfolder named for current date/time
;Then want to uploads that folder to the ftp site into a new folder by the same name
;  :(   wildcards failing on upload. 

$sDateTime = (@MON & "-" & @MDAY & "-" & @YEAR & " - " & @HOUR & "-" & @MIN)
DirCreate('c:\aflpics\' & $sDateTime)
FileMove('c:\aflpics\*.jpg', 'c:\aflpics\' & $sDateTime & '\*.jpg')

$server = 'localhost'
$username = filereadline('c:\program files\aflapp\currentuser.txt')
$pass = 'blah'

$Open = _FTPOpen('MyFTP')
if @error then
msgbox(0,"","fail_open")
endif
$Conn = _FTPConnect($Open, $server, $username, $pass)
if @error then
msgbox(0,"","fail_connect")
endif
$MKD = _FTPMakeDir($Conn, $sDateTime)
if @error then
msgbox(0,"","fail_Mkdir")
endif

;-------------------Problem Area---------------------
;works great like this

$Ftpp = _FtpPutFile($Conn, 'c:\aflpics\' & $sDateTime & '\DC001.jpg', '/' & $sDateTime & '/DC001.jpg')
if @error then
msgbox(0,"","fail_upload")
endif

;----------------------------------------
;fails upload like this

$Ftpp = _FtpPutFile($Conn, 'c:\aflpics\' & $sDateTime & '\*.jpg', '/' & $sDateTime & '/*.jpg')
if @error then
msgbox(0,"","fail_upload")
endif
;-------------------End Problem Area---------------------


$Ftpc = _FTPClose($Open)
if @error then
msgbox(0,"","fail_close")
endif
Link to comment
Share on other sites

you could use DIR to find all the possible matches and then upload them in a for loop.

How did you ever deal with it the first time? It must've been a pain I guess otherwise you probably would've done it in on this one. I'll do a loop, and an array and pick the cleanest looking one. I'll post what I come up with. Thanks again.

Link to comment
Share on other sites

This looks like a lot but it's not. I'm brand new to scripting, so theres nothing complicated.

Within you'll see my workaround to FTP (and FTP.au3) not liking the wildcard (*.jpg)

Theres a lot of specifics, so sorry, pick out what you need, email me with questions.

I really really love autoit.

 

#include <FTP.au3>

#Include <date.au3>

#include <File.au3>

#include <process.au3>

;Variables

$sDateTime = (@MON & "-" & @MDAY & "-" & @YEAR & " - " & @HOUR & "-" & @MIN)

$server = 'afl.no-ip.org'

$pass = 'Afl2005'

;Verifies that user is still the one listed in currentuser.txt

If Not IsDeclared('sUsername') Then Dim $sUsername

$sUsername = InputBox('Photo Transfer','What is your AFL Username?', FileReadLine('C:\Program Files\AFLAPP\CurrentUser.txt'),' M','-1','1','-1','-1')

Select

Case @Error = 0 ;OK - The string returned is valid

Case @Error = 1 ;The Cancel button was pushed

Exit

Case @Error = 3 ;The InputBox failed to open

EndSelect

;Overwrites previous username (regardless of change)

_FileCreate('C:\Program Files\AFLAPP\CurrentUser.txt')

FileWriteLine ('C:\Program Files\AFLAPP\CurrentUser.txt', $sUsername)

;Creates a text file listing of all .jpg files in the folder to upload 1 by 1

;Set number of characters to 10000. Wish there was an unlimited.

;Don't know if Huge numbers will slow script.

$sFileList = 'c:\aflpics\filelist.txt'

_FileCreate($sFileList)

_RunDOS('dir /s /b c:\aflpics\*.jpg > c:\aflpics\filelist.txt')

$slist = FileRead($sFileList,10000)

;Makes sure the files in the list are the ones you want

#Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question

If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer

$iMsgBoxAnswer = MsgBox(36,"Confirm:","Are these the files you want to transfer?" & @CR & @CR & $sList)

Select

Case $iMsgBoxAnswer = 6 ;Yes

Case $iMsgBoxAnswer = 7 ;No

Exit

EndSelect

#EndRegion --- CodeWizard generated code End ---

;Ftp operations, any error will exit the script.

;Creates a session name to use for multiple sessions i think

$Open = _FTPOpen('MyFTP')

if @error then

msgbox(0,"","fail_open")

Exit

endif

;Connects to ftp site

$Conn = _FTPConnect($Open, $server, $sUsername, $pass)

if @error then

msgbox(0,"Error:","Failed to connect to the server. Please contact the Administrator.")

Exit

endif

;Makes new folder labed by date/time: "10-10-2005 - 08-30" for "october 10th at 8:30"

$MKD = _FTPMakeDir($Conn, $sDateTime)

if @error then

msgbox(0,"Error:","Failed to create folder on the server. Please try again or contact the Administrator.")

Exit

endif

;Uploads all files in the list to the new folder and renames to Photo001.jpg, Photo002.jpg and so on.

;Using the original filenames would probably require about 20 more minutes.

$sTotal = _FileCountLines($sFileList)

$i=1

Do

$File = FileReadLine($sFileList, $i)

$Ftpp = _FtpPutFile($Conn, $File, '/' & $sDateTime & '/Photo00' & $i & '.jpg')

$i = $i + 1

if @error then

msgbox(0,"Error:","Failed to upload the files. Please contact the Administrator.")

Exit

endif

Until $i = $sTotal + 1

;Disconnects

$Ftpc = _FTPClose($Open)

if @error then

msgbox(0,"","fail_close")

Exit

endif

MsgBox(0,"Upload Success!",'Your photos have been uploaded to your photos folder on the server.' & @CR & @CR & _

'The originals will now be saved in the c:\aflpics\' & $sDateTime & '\ folder on your computer.')

;Creates new subfolder named with current date & time and moves files into it

DirCreate('c:\aflpics\' & $sDateTime)

FileMove('c:\aflpics\*.jpg', 'c:\aflpics\' & $sDateTime & '\*.jpg')

Exit

Link to comment
Share on other sites

  • 5 weeks later...

FTPGetFileSize DllCall Function is here

Hi Jezzzy,

needed something like that myself. I haven't coded for years, neither for windows (only DOS), but figured this one out. :( Using the FTPGetFileSize function I made, you can periodically check how many bytes have been uploaded to the server. You will need some multithreading function though. My idea is that you make a seperate executable for measuring the progress, call it 'progress.bin' or something and launch it with commandline args just before you initiate the FTP transfer command.

The only single threaded way to do this would probably be programming the byte-by-byte transfer DllCall function from scratch. Not my recommendation, since it would be slower than this solution.

Hopefully this helps you out. :P

LaKKie.

: EDIT :

Bad suggestion of mine up there. The filesize can be checked on most FTP's _only_ after the transfer has completed. :lmao:

To make a progressbar you'll have to think of something new. All my work was in vain... :)

I would love to integrate a progress bar into this to display current upload status. Has this been covered elsewhere already?

I.E. - a way to pull total num of bytes sent so I can plug that into a progress meter loop.

FTPGetFileSize.au3

Edited by LaKKie
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...