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 

Simple App to send file to an FTP server and copy http path

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Zac
Guest





PostPosted: Sat Apr 19, 2008 3:56 pm    Post subject: Simple App to send file to an FTP server and copy http path Reply with quote

Simple App to send file to an FTP server and copy http path of the file to clipboard with BBcode tags : [img] if file have image ext (.jpg.gif...) or [url] for others (for easy insert in forums) , app is made to run from windows "SendTo" menu


Code:

;(ftp code find on ahk forum, thanks to the man who made it)
FtpOpen(Server, Port=21, Username=0, Password=0 ,Proxy="", ProxyBypass="")
{
menu, Tray, Icon, status_icons.dll, 1
IfEqual, Username, 0, SetEnv, Username, anonymous
IfEqual, Password, 0, SetEnv, Password, anonymous

If (Proxy != "")
AccessType=3
Else
AccessType=1

menu, Tray, Icon, status_icons.dll, 8
sleep 300
menu, Tray, Icon, status_icons.dll, 1
sleep 100
menu, Tray, Icon, status_icons.dll, 8
sleep 200
menu, Tray, Icon, status_icons.dll, 1
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)
}

FtpPutFile(LocalFile, NewRemoteFile="", Flags=0) {
menu, Tray, Icon, status_icons.dll, 4
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
}
menu, Tray, Icon, status_icons.dll, 2
;TrayTip,,Initialisation...
sleep 1000

IfExist, Config.ini
{
IniRead, imgext , Config.ini, prefs, Ext_Images
If !imgext
   {
   SoundPlay,*64
   menu, Tray, Icon, status_icons.dll, 6
   TrayTip,Config error, Error images ext not set in Config.ini. `nNow exiting...,2,2,1000
   sleep,8000
   Exitapp
   }
IniRead, FTP_Remote_Host_name , Config.ini, prefs, FTP_Remote_Host_name
If !FTP_Remote_Host_name
   {
   SoundPlay,*64
   menu, Tray, Icon, status_icons.dll, 6
   TrayTip,Config error, Error host name not set in Config.ini. `nNow exiting...,2,2,1000
   sleep,8000
   Exitapp
   }
IniRead, FTP_Remote_Host_port , Config.ini, prefs, FTP_Remote_Host_port
If !FTP_Remote_Host_port
   {
   SoundPlay,*64
   menu, Tray, Icon, status_icons.dll, 6
   TrayTip,Config error, Error host port not set in Config.ini. `nNow exiting...,2,2,1000
   sleep,8000
   Exitapp
   }
IniRead, FTP_Remote_Host_user , Config.ini, prefs, FTP_Remote_Host_user
If !FTP_Remote_Host_user
   {
   SoundPlay,*64
   menu, Tray, Icon, status_icons.dll, 6
   TrayTip,Config error, Error user name not set in Config.ini. `nNow exiting...,2,2,1000
   sleep,8000
   Exitapp
   }
IniRead, FTP_Remote_Host_passwd , Config.ini, prefs, FTP_Remote_Host_passwd
If !FTP_Remote_Host_passwd
   {
   SoundPlay,*64
   menu, Tray, Icon, status_icons.dll, 6
   TrayTip,Config error, Error password not set in Config.ini. `nNow exiting...,2,2,1000
   sleep,8000
   Exitapp
   }
IniRead, HTTP_Remote_path , Config.ini, prefs, HTTP_Remote_path
If !HTTP_Remote_path
   {
   SoundPlay,*64
   menu, Tray, Icon, status_icons.dll, 6
   TrayTip,Config error, Error WWW path not set in Config.ini. `nNow exiting...,2,2,1000
   sleep,8000
   Exitapp
   }
}
else
{
SoundPlay,*64
menu, Tray, Icon, status_icons.dll, 6
TrayTip,Config error, Can't find Config.ini file. `nNow exiting...,2,2,1000
sleep,8000
Exitapp
}

ifexist %1%
{

   If (FtpOpen(FTP_Remote_Host_name, FTP_Remote_Host_port, FTP_Remote_Host_user, FTP_Remote_Host_passwd) != 1)
      {
   SoundPlay,*64
   menu, Tray, Icon, status_icons.dll, 6
     TrayTip,Connexion error, Can't connect to %FTP_Remote_Host_name%. `nNow exiting..,2,2,1000
   sleep,8000
   FtpClose()
     exitapp
     }
   Else
   {

   File_path=%1%
   SplitPath, File_path , remote_file
   If (FtpPutFile(File_path, remote_file, Flags=1) != 1)
        {
      SoundPlay,*64
      menu, Tray, Icon, status_icons.dll, 6
          TrayTip,Transfert error, An error ocured while transfering %remote_file%. `nNow exiting..,2,2,1000
      sleep,8000
      FtpClose()    
         exitapp
         }
   
   SplitPath, File_path ,,, file_ext
   if file_ext in %imgext%
      {
      Clipboard=[img]%HTTP_Remote_path%%remote_file%[/img]
      menu, Tray, Icon, status_icons.dll, 5
      TrayTip,BBCode "IMG" copied in clipboard.,[img]%HTTP_Remote_path%%remote_file%[/img],2,1,1000
      FtpClose()
      sleep,8000
      exitapp
      }
      else
      {
      Clipboard=[utl]%HTTP_Remote_path%%remote_file%[/url]
      menu, Tray, Icon, status_icons.dll, 5
      TrayTip,BBCode "URL" copied in clipboard.,[url]%HTTP_Remote_path%%remote_file%[/url],2,1,1000
      FtpClose()
      sleep,8000
      exitapp
      }




   }
}
SoundPlay,*64
menu, Tray, Icon, status_icons.dll, 6
TrayTip,Path error., Can't find the file: "%1%". `nNow exiting..,2,2,1000
sleep,8000
Exitapp



all files in the archive there:
http://befriendly.9online.fr/ftpsend.zip


Screenshot in french but the app is in english ^^
Back to top
Clash



Joined: 27 Jun 2006
Posts: 182

PostPosted: Sat Apr 19, 2008 5:07 pm    Post subject: Reply with quote

The image doesn't match what's on my pc, but my pc isn't vista - it's xp. Where do i need to copy the shortcut?
_________________
Back to top
View user's profile Send private message
Zac



Joined: 19 Apr 2008
Posts: 2

PostPosted: Sun Apr 20, 2008 4:26 pm    Post subject: Reply with quote

in your user folder there's a folder called SendTo... but to see it you must enable "Show hidden files" in In folders options. if you cant' copy in this folder change the proprietary of it to your user name
Back to top
View user's profile Send private message
Clash



Joined: 27 Jun 2006
Posts: 182

PostPosted: Mon Apr 21, 2008 5:38 pm    Post subject: Reply with quote

Oh i understand now. Thanks Smile. Cool app.
_________________
Back to top
View user's profile Send private message
badmojo



Joined: 11 Nov 2005
Posts: 150

PostPosted: Sun Aug 24, 2008 6:46 am    Post subject: Reply with quote

cool script! but my ftp server host doesn't allow me to upload to root folder. is there a way i can optionally put an sub-folder as part of Config.ini?

also if you could cater for other files such as zip, rar or txt, this program would be even more helpful. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
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