Morbihan
asked on
autohotkey script question
This script creates a window in which I shall be able to drag and drop files into, which then are uploaded to a server and directory specified in the appropriate fields.
Could you test it on your machine? If it does not work on your machine either I would ask a new 500 point question to figure out where the problem is.
Thank you very much in advance!
Could you test it on your machine? If it does not work on your machine either I would ask a new 500 point question to figure out where the problem is.
Thank you very much in advance!
;You can hardcode your settings in here so you don't have to type them all the time.
FTPURL = ;FTP URL.
FTPU = ;FTP User Name
FTPP = ;FTP Password
PORT = 21 ;FTP Port
remotelocation = public_html/uploads/copywriting/ ;Remote folder to drop files into.
weburl=http://www.dating-site-list.com/uploads/copywriting/ ;URL of the folder these files will be accessable from.
;If you don't want a GUI to always change your info just remove this section.
gui, add, text,,FTP URL
gui, add, edit,w400 h20,%FTPURL%
gui, add, text,,FTP User Name
gui, add, edit,w400 h20,%FTPU%
gui, add, text,,FTP Password
gui, add, edit,w400 h20,%FTPP%
gui, add, text,,Port
gui, add, edit,w40 h20,%PORT%
gui, add, text,,Remote folder to drop files into.
gui, add, edit,w400 h20,%remotelocation%
gui, add, text,,URL of the folder these files will be accessable from.
gui, add, edit,w400 h20,%weburl%
;Create GUI
gui, add, text,, Copy last to clipboard.
gui, add, checkbox, vclipboardcheck Checked
gui, add, text,, Open URL after upload.
gui, add, checkbox, vrunafter unChecked
gui, add, text, y+20 w400, Drop files to upload here.
gui, add, edit, readonly w400 h80 vstatus
gui, show,,Simple Folder FTP
return
;Process a file once you drop a file in.
GuiDropFiles:
gui, submit, nohide
Loop, parse, A_GuiControlEvent, `n
{
;get file name without path.
SplitPath, A_LoopField, name
;Connect and upload file.
FtpOpen(FTPURL, PORT, FTPU , FTPP)
FtpSetCurrentDirectory(remotelocation)
FtpPutFile(A_LoopField, name)
FtpClose()
;update status to show file uploaded
updatemsg(weburl name)
;Copy to Clipboard and Run Options
if(runafter=1)
run, %weburl%%name%
if(clipboardcheck=1)
clipboard=%weburl%%name%
}
Return
GuiClose:
GuiEscape:
ExitApp
updatemsg(msg)
{
gui, submit, nohide
global status
if (status <> " ")
updatestatus = %msg%`n%Status%
GuiControl, ,Status, %updatestatus%
}
;------------------------------------FTP Functions begin.------------------------------------
;FTP functions coded by olfen (http://www.autohotkey.com/forum/topic10393.html)
/*
http://msdn.microsoft.com/library/en-us/wininet/wininet/ftp_sessions.asp
http://msdn.microsoft.com/library/en-us/wininet/wininet/internetopen.asp
http://msdn.microsoft.com/library/en-us/wininet/wininet/internetconnect.asp
*/
FtpCreateDirectory(DirName) {
global ic_hInternet
r := DllCall("wininet\FtpCreateDirectoryA", "uint", ic_hInternet, "str", DirName)
If (ErrorLevel != 0 or r = 0)
return 0
else
return 1
}
FtpRemoveDirectory(DirName) {
global ic_hInternet
r := DllCall("wininet\FtpRemoveDirectoryA", "uint", ic_hInternet, "str", DirName)
If (ErrorLevel != 0 or r = 0)
return 0
else
return 1
}
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
}
FtpGetFile(RemoteFile, NewFile="", 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 NewFile=
NewFile := RemoteFile
global ic_hInternet
r := DllCall("wininet\FtpGetFileA"
, "uint", ic_hInternet
, "str", RemoteFile
, "str", NewFile
, "int", 1 ;do not overwrite existing files
, "uint", 0 ;dwFlagsAndAttributes
, "uint", Flags
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or r = 0)
return 0
else
return 1
}
FtpGetFileSize(FileName, Flags=0) {
;Flags:
;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
;FTP_TRANSFER_TYPE_ASCII = 1
;FTP_TRANSFER_TYPE_BINARY = 2
global ic_hInternet
fof_hInternet := DllCall("wininet\FtpOpenFileA"
, "uint", ic_hInternet
, "str", FileName
, "uint", 0x80000000 ;dwAccess: GENERIC_READ
, "uint", Flags
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or fof_hInternet = 0)
return -1
FileSize := DllCall("wininet\FtpGetFileSize", "uint", fof_hInternet, "uint", 0)
DllCall("wininet\InternetCloseHandle", "UInt", fof_hInternet)
return, FileSize
}
FtpDeleteFile(FileName) {
global ic_hInternet
r := DllCall("wininet\FtpDeleteFileA", "uint", ic_hInternet, "str", FileName)
If (ErrorLevel != 0 or r = 0)
return 0
else
return 1
}
FtpRenameFile(Existing, New) {
global ic_hInternet
r := DllCall("wininet\FtpRenameFileA", "uint", ic_hInternet, "str", Existing, "str", New)
If (ErrorLevel != 0 or r = 0)
return 0
else
return 1
}
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)
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER