Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FTP Class + Library [FTP as easy as 1-2-3]


  • Please log in to reply
40 replies to this topic
Sergio
  • Members
  • 516 posts
  • Last active: Dec 01 2017 04:46 PM
  • Joined: 16 Mar 2008

Very Useful!  Thanks!

 

At the risk of sounding obvious, how would I get multiple files with this method?  With FTP, I'd call mget.  Is there a similar command?  Or would I have to loop ftp1.GetFile somehow?


ahkFooter.png

IF YOU DO NOT GET ANSWERS HERE, TRY; HTTP://AHKSCRIPT.ORG/BOARDS


lagomorph
  • Members
  • 403 posts
  • Last active: May 15 2014 03:41 PM
  • Joined: 02 Apr 2010

For anyone else working on this, all of the code is saved here: https://github.com/s...r/Scriplets/FTP

 

You may need to enter PASSIVE mode to get FTP to work. I did! If you keep uploading 0kb "empty" files to your FTP, or getting timeout errors, then this is definitely what you need!

 

To use passive mode, edit your FTP.ahk library and change line 61 to this:

  ftp_$obj$.InternetConnectFlags := 0x08000000 ; Passive mode

This flag will set Shajul's FTP functions to use passive mode! No more empty files!



Tonya
  • Members
  • 11 posts
  • Last active: May 09 2014 06:20 PM
  • Joined: 04 Jan 2011

For anyone else working on this, all of the code is saved here: https://github.com/s...r/Scriplets/FTP

 

You may need to enter PASSIVE mode to get FTP to work. I did! If you keep uploading 0kb "empty" files to your FTP, or getting timeout errors, then this is definitely what you need!

 

To use passive mode, edit your FTP.ahk library and change line 61 to this:

  ftp_$obj$.InternetConnectFlags := 0x08000000 ; Passive mode

This flag will set Shajul's FTP functions to use passive mode! No more empty files!

 

Wow I found this hint...  I feel very close to an answer to my problem. I've read over this entire topic and i didn't think I was on the right track and then boom... there it was!  The only problem is, I used the AHK documents to create my ftp script from scratch so my code doesn't look anything like the code in this topic. So I'm a little lost on how to apply your solution to my problem.

 

I didn't want to just post code here and change the course of this topic, but I do need just a little help with the 0kb "empty file" on upload issue.  Obviously I need to change the mode to passive just as you say.

 

Everything on my script works great except for that.  I get 0kbs uploaded.  Is it appropriate for me to post code here within this topic or should I do that in a new topic or private messaging?



ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006

cool stuff!


Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

magusneo
  • Members
  • 51 posts
  • Last active: May 10 2014 03:15 PM
  • Joined: 30 May 2012

oFTP.GetCurrentDirectory doesn't work for me in AHK_L 1.1.13.0.

It will work after I replace

r := DllCall("wininet\FtpGetCurrentDirectory", "PTR", this.hInternet, "Ptr", &ic_currdir, "UIntP", &nSize)

with

r := DllCall("wininet\FtpGetCurrentDirectory", "PTR", this.hInternet, "Ptr", &ic_currdir, "UIntP", nSize)


Albireo
  • Members
  • 558 posts
  • Last active: Dec 13 2019 02:02 PM
  • Joined: 01 Feb 2006

I say as many other, very useful!

But I have a problem, maybe it depends on the FTP-server?

I use this MsgBox .:

MsgBox 64, %A_ScriptName% - Rad %A_LineNumber%, % "Name : " . item.Name
 . "`nCreationTime : " . item.CreationTime
 . "`nLastAccessTime : " . item.LastAccessTime
 . "`nLastWriteTime : " . item.LastWriteTime
 . "`nSize : " . item.Size
 . "`nAttribs : " . item.Attribs
Loop
{
  if !(item := FTP_FindNextFile())
    break
  MsgBox 64, %A_ScriptName% - Rad %A_LineNumber%, % "Name : " . item.Name
   . "`nCreationTime : " . item.CreationTime
   . "`nLastAccessTime : " . item.LastAccessTime
   . "`nLastWriteTime : " . item.LastWriteTime
   . "`nSize : " . item.Size
   . "`nAttribs : " . item.Attribs
}

When I want to get information of the files on the FTP-server.

I can't get more than .:
- Name of the file.
- Size of the file.
- and the Atribut.
I miss .:
- Creation Time
- Last Access Time
- and Last Write Time.

Is it because I just "played" with pictures?

 

//Jan
 

 



ozzii
  • Members
  • 167 posts
  • Last active: Oct 30 2015 04:54 PM
  • Joined: 23 Mar 2011
Hi, yes, very useful. One suggestion : Have the possibility to use it with 'sftp' (preferably the one from putty) I don't have the skills to do it myself ;(

Albireo
  • Members
  • 558 posts
  • Last active: Dec 13 2019 02:02 PM
  • Joined: 01 Feb 2006

Hello!

I still have problems to read in the FTP-catalogue.:

- Creation Time
- Last Access Time
- and Last Write Time.

 

My program is .:

;; FTP Class Example - http://www.autohotkey.com/forum/viewtopic.php?t=73544
;; Passive mode
;; Synchronous mode example

;;== USER SETTINGS ===============
Server     := "xxx.xxx.xxx.xxx"
UserName   := "UserName_yyy"
Password   := "xxxyyy123"
UploadFile := "c:\Temp\Testfile.txt"
;;== END USER SETTINGS ===========


#Include FTPv2.ahk

ftp1 := new FTP()
ftp1 ? TTip("InternetOpen Success") : Quit("Could not load module/InternetOpen")

; connect to FTP server
ftp1.Open(Server, UserName, Password) ? TTip("Connected to FTP") : Quit(ftp1.LastError)

; get current directory
sOrgPath := ftp1.GetCurrentDirectory()
sOrgPath ? TTip("GetCurrentDirectory : " sOrgPath) : Msg(ftp1.LastError)
  
; create a new directory 'testing'
ftp1.CreateDirectory("testing") ? TTip("Created Directory ""testing""") : Msg(ftp1.LastError)

; set the current directory to 'root/testing'
ftp1.SetCurrentDirectory("testing") ? TTip("SetCurrentDirectory ""testing""") : Msg(ftp1.LastError)

; upload this script file
ftp1.PutFile(A_ScriptFullPath, A_ScriptName) ? TTip("PutFile success!") : Msg(ftp1.LastError)

; rename script to 'mytestscript.ahk'
ftp1.RenameFile(A_ScriptName, "MyTestScript.ahk") ? TTip("RenameFile success!") : Msg(ftp1.LastError)

; enumerate the file list from the current directory ('root/testing')
TTip("Enumerating files in directory ""/testing/""")
item := ftp1.FindFirstFile("/testing/*")	;*/;
MsgBox 64, %A_ScriptName% - Rad %A_LineNumber%, % "Name : " . item.Name	;%;
 . "`nCreationTime : " . item.CreationTime
 . "`nLastAccessTime : " . item.LastAccessTime
 . "`nLastWriteTime : " . item.LastWriteTime
 . "`nSize : " . item.Size
 . "`nAttribs : " . item.Attribs
Loop
{
  if !(item := ftp1.FindNextFile())
    break
  MsgBox 64, %A_ScriptName% - Rad %A_LineNumber%, % "Name : " . item.Name ;%;
   . "`nCreationTime : " . item.CreationTime
   . "`nLastAccessTime : " . item.LastAccessTime
   . "`nLastWriteTime : " . item.LastWriteTime
   . "`nSize : " . item.Size
   . "`nAttribs : " . item.Attribs
}

; retrieve the file from the FTP server
ftp1.GetFile("MyTestScript.ahk", A_ScriptDir . "\MyTestScript.ahk", 0) ? TTip("GetFile success!") : Msg(ftp1.LastError)

; delete the file from the FTP server
ftp1.DeleteFile("MyTestScript.ahk") ? TTip("DeleteFile success!") : Msg(ftp1.LastError)

; upload a file with progress
ftp1.InternetWriteFile( UploadFile ) ? TTip("InternetWriteFile success!") : Msg(ftp1.LastError)

; download a file with progress
SplitPath,UploadFile,fName,,fExt
ftp1.InternetReadFile( fName , "delete_me." fExt) ? TTip("InternetReadFile success!") : Msg(ftp1.LastError)

; delete the file
ftp1.DeleteFile( fName )  ? TTip("DeleteFile success!") : Msg(ftp1.LastError)

; set the current directory back to the root
ftp1.SetCurrentDirectory(sOrgPath) ? TTip("SetCurrentDirectory to original path: success!") : Msg(ftp1.LastError)

; remove the direcrtory 'testing'
ftp1.RemoveDirectory("testing") ? TTip("RemoveDirectory ""\testing"" success!") : Msg(ftp1.LastError)

; close the FTP connection, free library
ftp1 := ""    ;__Delete called
MsgBox 64, %A_ScriptName% - Rad %A_LineNumber% - Success, Tests successfully completed!, 3
ExitApp


Quit(Message="") {
	if Message
		MsgBox 16, %A_ScriptName% - Rad %A_LineNumber% - Error!, %Message%, 5
	ExitApp
}

Msg(Message="") {
	MsgBox 64, %A_ScriptName% - Rad %A_LineNumber%, %Message%, 5
}

TTip(Message="") {
	ToolTip %Message%
}

Do I have something wrong in my code?

Is there any other way to read information on the files on an FTP server?

 

//Jan



Albireo
  • Members
  • 558 posts
  • Last active: Dec 13 2019 02:02 PM
  • Joined: 01 Feb 2006

Still problem to use FTP with AHK!

(I have used the program above)

Login is no problem.

But I can't

- Read the creation time of a file!

- Create new directory.
(and maybe something more)//Jan



jaywissy
  • Members
  • 1 posts
  • Last active: Jun 28 2015 01:43 PM
  • Joined: 28 Jun 2015
Pls how can I upload a track

fickle87
  • Members
  • 4 posts
  • Last active: Aug 23 2015 08:05 AM
  • Joined: 10 Feb 2013

Uploaded successfully But file names are broken

 

How to change FileEncoding?

 

May I use character set as UTF-8?