[Class] FTP
-
- Posts: 75
- Joined: 06 Oct 2016, 15:57
Re: [Class] FTP
Also the "experimental" FindFiles() method works perfectly in my own testing/usage. It was super helpful for this project. Thanks again for providing such an excellent class library
-
- Posts: 7
- Joined: 30 Nov 2023, 01:32
Re: [Class] FTP
tyty needed this function too, u saved me hours of workShatterCoder wrote: ↑09 Jun 2023, 15:39I'd like to submit an addition to the class: FIleRead() which allows you to read a file from the FTP server directly to a variable without needing to write to disk.
I'm not sure how many people will have need of this particular method, but for myself it was needed because I was having to look through multiple files on an FTP server per second to look for a specific string so avoiding disk read/write time was essential.Code: Select all
ReadFile(hConnect, FileName) { static GENERIC_READ := 0x80000000 if (hFile := this.OpenFile(hConnect, FileName, GENERIC_READ)) { data_out := "" chunksize := 1024 ;chunk size to request per dllcall VarSetCapacity(buf, chunksize ) VarSetCapacity(bytes_read, 4 * 4) ;dword bytes_read := 0 while (DllCall("wininet\InternetReadFile", "ptr", hFile, "Uptr", &buf, "uint", chunksize , "ptr", &bytes_read) && bytes_read) data_out .= StrGet(&Buf + 0, "UTF-8") this.InternetCloseHandle(hFile) return data_out } return false }
example usage:
Code: Select all
hFTP := FTP.Open("AHK-FTP") hSession := FTP.Connect(hFTP, "ftp.example.com", 21, "user", "passwd") Filecontent := FTP.ReadFile(hSession, "testfile.txt") msgbox, % Filecontent FTP.Disconnect(hSession) FTP.Close(hFTP)
-
- Posts: 75
- Joined: 06 Oct 2016, 15:57
Re: [Class] FTP
Glad someone else could benefit from my pain
-
- Posts: 7
- Joined: 30 Nov 2023, 01:32
Re: [Class] FTP
just to add, i had to reduce chunksize in ReadFile(hConnect, FileName)
from 1024 to 512/256, else it was intermittently working with my ftp servers,
was dealing with files the size 100+ bytes though.
HF GL