AutoHotkey Community

It is currently May 27th, 2012, 10:05 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 98 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7
Author Message
 Post subject:
PostPosted: February 2nd, 2011, 6:29 pm 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
Thanks for testing and finding the bug..

I have corrected it. Anyway, i've sent you a pm also with the details..

_________________
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2011, 4:07 am 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
I can't get it to work. I keep getting the "Error uploading file" message. My .net account shows the file, but it's 0KB. Any ideas?

Code:
; sample values
FtpHost = autohotkey.net
FtpPort = 21
FtpUsername = MyUsername
FtpPassword = MyPassword
localFile = C:\FtpTest.txt ; I created this file so that it exists
remoteFile = FtpTest.txt ; I have tried putting a "/" before the file name. It doesn't seem to matter though.

Gosub, uploadFile ; go directly to uploading the file since the subroutine contains the connection.

; establish connection to FTP server
connect:
   FtpConnection := FtpOpen(FtpHost, FtpPort, FtpUsername, FtpPassword)
   If (FtpConnection != 1)
   {
      MsgBox, Error connecting to FTP server.
      GoSub, quit
   }
Return

; upload file
uploadFile:
    ; establish connection to FTP server
   GoSub, connect
   ; store file on FTP server
   fileTransfer := FtpPutFile(localFile, remoteFile)
   If (fileTransfer != 1)
   {
      MsgBox, Error uploading file.
      GoSub, quit
   }
   ; close connection
   FtpClose()
   ; confirmation message
   MsgBox, Upload complete.
   ; terminate script
   GoSub, quit
Return

; download file
downloadFile:
    ; establish connection to FTP server
   GoSub, connect
   ; retrieve file from FTP server
   fileTransfer := FtpGetFile(remoteFile, localFile)
   If (fileTransfer != 1)
   {
      MsgBox, Error downloading file.
      GoSub, quit
   }
   ; close connection
   FtpClose()
   ; confirmation message
   MsgBox, Download complete.
   ; terminate script
   GoSub, quit
Return

quit:
ExitApp

;;;; THE BELOW CODE IS FROM THE LIBRARY - just to make this a runnable example

/*
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)
}


And, thanks to nimda for providing me with the idea and original code and thread.

_________________
-Jeremiah


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2011, 5:10 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
are you using ahk basic?

_________________
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Progress Bar
PostPosted: July 5th, 2011, 6:27 pm 
OK, I know this topic is old, but I'm needing to know if anyone has the script code for a progress bar in this program. I have the gui done (i think), but i need help with the coding. From what I have so far, this is it:
Code:
;You can hardcode your settings in here so you don't have to type them all the time.
FTPURL = xxx.xxxxxxxxx.xxx                           ;FTP URL.
FTPU = xxxxxxxxxx                              ;FTP User Name
FTPP = xxxxxxxxxx                              ;FTP Password
PORT = 21                              ;FTP Port
remotelocation = /storage/public/                     ;Remote folder to drop files into.
weburl=http://tyedwards.com/storage/public/                        ;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, Add, Text, x6 y470 w50 h20 , Progress:
Gui, Add, Progress, x6 y490 w400 h20 , 0
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)
}

Thanks!
Ty Edwards :D
wireproof@gmail.com

Note: Post modified to redact information. ~ sinkfaze


Report this post
Top
  
Reply with quote  
 Post subject: Sorry...
PostPosted: July 5th, 2011, 6:30 pm 
Sorry, computer posted to wrong fourm... :oops:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 6th, 2011, 2:01 am 
Please edit the guest's post.

Thanks.

Note: Post modified to redact information. ~ sinkfaze


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2011, 8:13 am 
Offline

Joined: May 23rd, 2009, 4:48 am
Posts: 363
Location: north bay, california
anyone make an ahk-basic version of HotKeyIt's InternetTimeToSystemTime()?

i get nonsense from it and haven't figured out structures yet...
thanks
- gwarble


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 7th, 2011, 8:42 am 
Offline

Joined: September 15th, 2006, 10:25 am
Posts: 567
gwarble wrote:
anyone make an ahk-basic version of HotKeyIt's InternetTimeToSystemTime()?

i get nonsense from it and haven't figured out structures yet...
thanks
- gwarble


Try this (not tested)..
Code:
   GetFileInfo(ByRef @FindData) {
   s := ""
   VarSetCapacity(ftstr, 8)
   DllCall("RtlMoveMemory", "str", ftstr, "uint", &@FindData + 4, "uint", 8)
   s .= "CreationTime = " . FileTimeToStr(ftstr)
   DllCall("RtlMoveMemory", "str", ftstr, "uint", &@FindData + 12, "uint", 8)
   s .= "`nLastAccessTime = " . FileTimeToStr(ftstr)
   DllCall("RtlMoveMemory", "str", ftstr, "uint", &@FindData + 20, "uint", 8)
   s .= "`nLastWriteTime = " . FileTimeToStr(ftstr)
   return s
   }
   
   FileTimeToStr(FileTime) {
      VarSetCapacity(SystemTime, 16, 0)
      If (!NumGet(FileTime,"UInt") && !NumGet(FileTime,4,"UInt"))
       Return 0
      DllCall("FileTimeToSystemTime", "PTR", &FileTime, "PTR", &SystemTime)
      Return NumGet(SystemTime,6,"short") ;date
        . "/" . NumGet(SystemTime,2,"short") ;month
        . "/" . NumGet(SystemTime,0,"short") ;year
        . " " . NumGet(SystemTime,8,"short") ;hours
        . ":" . ((StrLen(tvar := NumGet(SystemTime,10,"short")) = 1) ? "0" . tvar : tvar) ;minutes
        . ":" . ((StrLen(tvar := NumGet(SystemTime,12,"short")) = 1) ? "0" . tvar : tvar) ;seconds
   ;      . "." . NumGet(SystemTime,14,"short") ;milliseconds
   }

_________________
If i've seen further it is by standing on the shoulders of giants

my site | ~shajul | WYSIWYG BBCode Editor


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 98 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group