AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DllCall: Basic FTP Functions
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
flyingDman



Joined: 27 Feb 2009
Posts: 690
Location: Burbank, California

PostPosted: Wed Mar 17, 2010 7:36 pm    Post subject: Reply with quote

there are 4 key elements. Check below
Code:
hConnect:=FTP_Open(host, 21, id, pw)                 ;underscore
FTP_PutFile(hConnect, fl2snd, target)                 ; underscore
FTP_CloseSocket(hConnect)                             ; missing
FTP_Close()                                  ;undescore


Is there anyone who has had luck with FTP_GetCurrentDirectory ?
Back to top
View user's profile Send private message
drainx1



Joined: 10 Apr 2009
Posts: 139
Location: Wichita,Kansas

PostPosted: Thu Mar 18, 2010 1:39 am    Post subject: Reply with quote

thanks for that, but i was refering to the first code, the original post. but with the other code, it doesnt upload. if anyone could help that would be helpfull.
_________________
Drainx1
Your favorite.

What says that we aren't a visualization of someones dream?
And that person could change the laws of physics without thinking a thing about it.
They could recreate the world, and not know what happened.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Guest_from_Germany
Guest





PostPosted: Wed Apr 07, 2010 4:48 pm    Post subject: Reply with quote

First, sorry for my bad english... Sad+

I've used the ftp functions. These functions are working fine with Autohotkey. I need for my actual project unicode support and so I've changed to AutohotKey_L. I have with this version a problem. I get the internet handle fine, but with this handle i can't open an ftp connection. I get the error 12007 - The server name could not be resolved.

The server name is ftp.strato.com and i see here no problem with the solving of this server name. Who can help? Is there a unknown problem with Autohotkey_L?

Thanks a lot
M'o
Back to top
Guest_from_Germany
Guest





PostPosted: Wed Apr 07, 2010 4:55 pm    Post subject: Reply with quote

Here the local variables:

Local Variables for FtpOpen()
--------------------------------------------------
AccessType[1 of 3]: 3
Err_code[5 of 7]: 12007
error_line_number[0 of 0]:
Error_msg[0 of 0]:
OutputVar[0 of 0]:
Password[7 of 7]: xxxxxxx
Port[2 of 3]: 21
Proxy[1 of 3]: 1
ProxyBypass[1 of 3]: 1
Server[14 of 63]: ftp.strato.com
Username[26 of 63]: ftp_xxxx@xxxx.de

And the last code lines:
031: if FtpOpen(ftpServer, ftpPort, ftpUser, ftpPass ,Proxy="", ProxyBypass="")
115: if Username = 0
116: if Password = 0
117: SB_SetText("Baue Verbindung zum Server auf...")
118: if (Proxy != "")
119: AccessType = 3
128: hModule := DllCall("LoadLibrary", "str", "wininet.dll")
130: io_hInternet := DllCall("wininet\InternetOpenA", "str", A_ScriptName, "UInt", AccessType, "str", Proxy, "str", ProxyBypass, "UInt", 0)
137: if (ErrorLevel != 0 || io_hInternet = 0)
142: ic_hInternet := DllCall("wininet\InternetConnectA", "uint", io_hInternet, "str", Server, "uint", Port, "str", Username, "str", Password, "uint" , 1, "uint", 0, "uint", 0) (2.56)
152: Err_code := DllCall("GetLastError")
154: MsgBox,%Err_code% (1.51)
Back to top
Guest_from_Germany
Guest





PostPosted: Wed Apr 07, 2010 5:00 pm    Post subject: Reply with quote

Additional, I get with the ANSI-Version no errors, so I use this version for my project. But I think, this is an error in the Autohotkey_L-UniCode-Version...
Back to top
IsNull



Joined: 10 May 2007
Posts: 593
Location: .switzerland

PostPosted: Wed Apr 07, 2010 7:59 pm    Post subject: Reply with quote

hi,

Code:
wininet\InternetConnectA


The A suffix means the ANSI Version of this function, but AHK_L is using Unicode by default.

So you have to use the unicode pendants I sugest. Smile



For example:
Quote:
InternetConnectW (Unicode) and InternetConnectA (ANSI)

_________________
http://securityvision.ch
AHK 2D GAME ENGINE
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Thu Apr 08, 2010 5:55 am    Post subject: Reply with quote

@IsNull: Thanks a lot. This solves my problem... Smile
Back to top
tov
Guest





PostPosted: Tue May 11, 2010 5:24 pm    Post subject: Reply with quote

Hi

Using FTP_DeleteFile(hConnect,FileName)

Can I wipe a directory ?

like

FTP_DeleteFile(hConnect,*.*) ??

Thanks Smile
Back to top
tov
Guest





PostPosted: Sat May 15, 2010 3:28 pm    Post subject: Reply with quote

Can anyone advise how to add a progress bar to the FTP download ??

Could it be done with this :
http://www.autohotkey.com/forum/topic11398.html&highlight=ftp+progress

How ?

Thanks Smile
Back to top
webster14



Joined: 02 Jul 2010
Posts: 17

PostPosted: Mon Jul 05, 2010 10:08 am    Post subject: FTP file write Reply with quote

Can anyone tell me how I can ad some text to a txt file on a host without downloading it and then uploading it again?

I've searched the forum but haven't found a FTP write function
Back to top
View user's profile Send private message
little Fairy
Guest





PostPosted: Mon Jul 05, 2010 10:24 am    Post subject: Reply with quote

Quote:
Can anyone tell me how I can ad some text to a txt file on a host without downloading it and then uploading it again?
You canīt.
Itīs not implemented in FTP .
Back to top
kiropes



Joined: 21 Mar 2007
Posts: 71

PostPosted: Mon Jul 05, 2010 10:43 am    Post subject: Re: FTP file write Reply with quote

webster14 wrote:
Can anyone tell me how I can ad some text to a txt file on a host without downloading it and then uploading it again?

I've searched the forum but haven't found a FTP write function



you can do with ftp.exe


Code:

open "url"
user  "user" "passw"
append "local txt file" "ftp server txt file"


Back to top
View user's profile Send private message
Maestr0



Joined: 18 Oct 2008
Posts: 159

PostPosted: Mon Jul 05, 2010 1:57 pm    Post subject: Reply with quote

drainx1 wrote:
thanks for that, but i was refering to the first code, the original post. but with the other code, it doesnt upload. if anyone could help that would be helpfull.


I got this to work, I needed something to upload a single file only, wanted it into a single exe so the user doesn't need to know the password:

Code:

server = ftp.autohotkey.com
port = 21
user = username_here
password = password_here
remotedir = remotedir_here
local = local_filename_here
remotefile = %local%

ifnotexist %local%
{
   Msgbox , The file "%local%" is missing in "%A_ScriptDir%".`n`nPlease copy the file to "%A_ScriptDir%" and restart this program.`n`nThis program will now close.
   exitapp
}

FtpOpen(server,port,user,password)
FtpSetCurrentDirectory(remotedir)
FtpPutFile(local,remotefile)
FtpClose()

exitapp

FtpOpen(Server, Port=21, Username=0, Password=0 ,Proxy="", ProxyBypass="") {
IfEqual, Username, 0, SetEnv, Username, anonymous
IfEqual, Password, 0, SetEnv, Password, anonymous

If (Proxy != "")
AccessType=3
Else
AccessType=1
;#define INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
;#define INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
;#define INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
;#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS

global ic_hInternet, io_hInternet, hModule
hModule := DllCall("LoadLibrary", "str", "wininet.dll")

io_hInternet := DllCall("wininet\InternetOpenA"
, "str", A_ScriptName ;lpszAgent
, "UInt", AccessType
, "str", Proxy
, "str", ProxyBypass
, "UInt", 0) ;dwFlags

If (ErrorLevel != 0 or io_hInternet = 0) {
FtpClose()
return 0
}

ic_hInternet := DllCall("wininet\InternetConnectA"
, "uint", io_hInternet
, "str", Server
, "uint", Port
, "str", Username
, "str", Password
, "uint" , 1 ;dwService (INTERNET_SERVICE_FTP = 1)
, "uint", 0 ;dwFlags
, "uint", 0) ;dwContext

If (ErrorLevel != 0 or ic_hInternet = 0)
return 0
else
return 1
}

FtpClose() {
global ic_hInternet, io_hInternet, hModule
DllCall("wininet\InternetCloseHandle",  "UInt", ic_hInternet)
DllCall("wininet\InternetCloseHandle",  "UInt", io_hInternet)
DllCall("FreeLibrary", "UInt", hModule)
}

FtpSetCurrentDirectory(DirName) {
global ic_hInternet
r := DllCall("wininet\FtpSetCurrentDirectoryA", "uint", ic_hInternet, "str", DirName)
If (ErrorLevel != 0 or r = 0)
return 0
else
return 1
}

FtpPutFile(LocalFile, NewRemoteFile="", Flags=0) {
;Flags:
;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
;FTP_TRANSFER_TYPE_ASCII = 1
;FTP_TRANSFER_TYPE_BINARY = 2
If NewRemoteFile=
NewRemoteFile := LocalFile
global ic_hInternet
r := DllCall("wininet\FtpPutFileA"
, "uint", ic_hInternet
, "str", LocalFile
, "str", NewRemoteFile
, "uint", Flags
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or r = 0)
return 0
else
return 1
}
Back to top
View user's profile Send private message
drainx1



Joined: 10 Apr 2009
Posts: 139
Location: Wichita,Kansas

PostPosted: Mon Jul 05, 2010 3:29 pm    Post subject: Reply with quote

Awesome. thats works perfectly!
Thanks!
_________________
Drainx1
Your favorite.

What says that we aren't a visualization of someones dream?
And that person could change the laws of physics without thinking a thing about it.
They could recreate the world, and not know what happened.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Maestr0



Joined: 18 Oct 2008
Posts: 159

PostPosted: Mon Jul 05, 2010 5:28 pm    Post subject: Reply with quote

drainx1 wrote:
Awesome. thats works perfectly!
Thanks!


you're welcome. You could achieve the same with FileAppend and FTP:
http://www.autohotkey.com/docs/commands/FileAppend.htm
Code:
; The following example demonstrates how to automate FTP uploading using the operating
; system's built-in FTP command. This script has been tested on Windows XP and 98se.

FTPCommandFile = %A_ScriptDir%\FTPCommands.txt
FTPLogFile = %A_ScriptDir%\FTPLog.txt
FileDelete %FTPCommandFile%  ; In case previous run was terminated prematurely.

FileAppend,  ; The comma is required in this case.
(
open host.domain.com
username
password
binary
cd htdocs
put %VarContainingNameOfTargetFile%
delete SomeOtherFile.htm
rename OldFileName.htm NewFileName.htm
ls -l
quit
), %FTPCommandFile%

RunWait %comspec% /c ftp.exe -s:"%FTPCommandFile%" >"%FTPLogFile%"
FileDelete %FTPCommandFile%  ; Delete for security reasons.
Run %FTPLogFile%  ; Display the log for review.

But I don't like that the password is in a file that was written to the drive and can be "undeleted".
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 5 of 7

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group