[Class] FTP
-
- Posts: 145
- 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: 145
- 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
Re: [Class] FTP
Will this script be adapted to AHK 2.0?
Re: [Class] FTP
I'll take a look at it. However, FTP has been considered unsafe for years. It's best to use SFTP.
[AHK] v2.0.18 | [WIN] 11 Pro (23H2) | [GitHub] Profile
Re: [Class] FTP
True, but in my case the information is encrypted. Maybe there is a similar AHK solution for SFTP?
Don't know if it's difficult, but one thing I noticed is that it gets the same error message regardless of whether the IP address is incorrect, or if the user / password is incorrect.
Then it takes quite a long time (in uncertainty) before the error message appears. (has the program hung or - what happens?...)
Don't know if it's difficult, but one thing I noticed is that it gets the same error message regardless of whether the IP address is incorrect, or if the user / password is incorrect.
Then it takes quite a long time (in uncertainty) before the error message appears. (has the program hung or - what happens?...)
-
- Posts: 3
- Joined: 28 Sep 2024, 06:15
Re: [Class] FTP
Guys, please help, show an example how to get the date of creation (upload) of a file FTP server.
-
- Posts: 3
- Joined: 28 Sep 2024, 06:15
Re: [Class] FTP
I've been looking for an answer for days now, this option just shows a random time.
Code: Select all
hFTP := FTP.Open("AHK-FTP")
hSession := FTP.Connect(hFTP, "Server", 21, "UserName", "Password")
item := FTP.FindFirstFile(hSession,"/upload/1.txt")
MsgBox % "Name : " . item.Name
. "`nCreationTime : " . item.CreationTime
. "`nLastAccessTime : " . item.LastAccessTime
. "`nLastWriteTime : " . item.LastWriteTime
FTP.Disconnect(hSession)
FTP.Close(hFTP)
#Include FTP.ahk
-
- Posts: 3
- Joined: 28 Sep 2024, 06:15
Re: [Class] FTP
I solved the problem this way!Andreichxxx wrote: ↑28 Sep 2024, 07:20Guys, please help, show an example how to get the date of creation (upload) of a file FTP server.
Code: Select all
hFTP := FTP.Open("AHK-FTP")
hSession := FTP.Connect(hFTP, "Serv", 21, "Name", "Passw")
for k, File in FTP.FindFiles(hSession,"/upload/Soft/1.txt")
MsgBox % ""
. "`nFile name : " . File.FileName
. "`nDate of file modification : " . File.LastWriteTime
FTP.Disconnect(hSession)
FTP.Close(hFTP)
#Include FTP.ahk
Re: [Class] FTP
Thanks for your posts.
Will test if it can work for me too.
Will test if it can work for me too.
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 135 guests