FTP Uploader

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

FTP Uploader

Post by Phil Pendlebury » Fri Feb 05, 2010 3:28 pm

Hello there,

Here is a script that deals with uploading to FTP sites. It works on single files but has some very neat features.

Image

What does this do?

It will help you upload your files to a remote FTP server. You can use a local file or a web address.

Copies the URL plus image tags to your clipboard so you can easily paste them to a forum or into HTML

You can use multiple FTP servers and the path for each server is remembered.

It keeps a log file for each server's activity.

Please read the instructions carefully.

I am posting this for two reasons.

1. A lot of people in a group I belong to have found it very handy and I have added all of their suggestions.
2. There are some neat little tricks that MS can do that some people may find useful.

As is often the case for me, this script grew from a very small idea. So the code has got a bit messy and could probably be rebuilt more efficiently. If anyone would like to do that of course you are more than welcome.

Please note:

To download the full script with a proper installer and manual go here:

Download: http://www.pendlebury.biz/applications/

If you attempt to run the script you will need to make your own ftp.ini file in the correct place and you will need to manually add the shortcut to the sendto location.

I would suggest that anyone who is interested can install the proper version but also reference this code to see what's going on.

Then feel free to post in the normal forum with questions, ideas, suggestions etc.

All the best.

Phil.

(Code in next post)
Last edited by Phil Pendlebury on Fri Feb 26, 2010 2:19 pm, edited 5 times in total.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Fri Feb 05, 2010 3:30 pm

Code: Select all

// FTP Uploader by Phil Pendlebury - http://www.pendlebury.biz

Let>RP_ADMIN=1
Let>APP_TITLE=FTP Uploader
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>MSG_WIDTH=360
Let>MSG_HEIGHT=260
Let>WF_TYPE=1
Let>VAREXPLICIT=0
Let>CF_OVERWRITE=1
Let>FTP_TIMEOUT=17
Let>PRESS_ALLOWVARS=1
Let>version=Version 3.55 - 08 March 2010
//
GetEnvVar>APPDATA,FTPINIFILE
Let>FTPINIFILE=%FTPINIFILE%\Phil Pendlebury\FTP Uploader

IfFileExists>%FTPINIFILE%\ftp.ini
  GOTO>iniexists
ELSE
  MDL>Could not find FTP.INI file!%CRLF%%CRLF%Please install the application correctly. Or create this file in the correct location and add some relevant data.%CRLF%%CRLF%OK to Quit.
  GOTO>Exit
ENDIF
Label>iniexists
//
Let>def_file=
Let>webupload=False
//
Separate>command_line," ,cmd_var
IF>cmd_var_2=
 Let>fromsendto=False
ELSE
 Let>def_file=cmd_var_2
 StringReplace>def_file,",,def_file
 Let>fromsendto=True
ENDIF
//
Let>choice_string=
//
Let>info_count=1
Label>choice_loop
ReadIniFile>%FTPINIFILE%\ftp.ini,%info_count%,server_name,choice_%info_count%
IF>choice_%info_count%=
  GOTO>choicemade
ENDIF
Let>actual_choice=choice_%info_count%
Let>choice_string=%choice_string%%actual_choice%%CRLF%
Let>info_count=info_count+1
GOTO>choice_loop
//
Label>choicemade
//
Dialog>ChooserDialog
   Caption=Choose FTP
   Width=263
   Height=160
   Top=CENTER
   Left=CENTER
   Max=0
   Min=0
   Close=0
   Resize=0
   ComboBox=msComboBox1,101,35,148,%choice_string%
   Label=Basic FTP Manager by Phil Pendlebury,8,8,true
   Label=Choose FTP Site:,8,40,true
   Button=QUIT,8,72,73,33,3,,Bugger off!
   Button=Go!,176,72,73,33,4,,Go on then
   Button=NEW,92,72,73,33,6,,Create a new FTP address
   MainMenu=Menu,About(30),Manual(40),Developers(50),WWW(60),Quit(3)
EndDialog>ChooserDialog


//
Show>ChooserDialog
Label>ChooseLoop
  GetDialogAction>ChooserDialog,ress
  Let>ftp_site=%ChooserDialog.msComboBox1%
  IF>ress=4,continue
  IF>ress=3,Exit
  IF>ress=6,makenew
  IF>ress=30
    MDL>FTP Uploader by Phil Pendlebury%CRLF%%CRLF%%version%
    RDA>ChooserDialog
  ENDIF
  IF>ress=40
    Executefile>%FTPINIFILE%\ftpuploader.chm
    RDA>ChooserDialog
  ENDIF
  IF>ress=50
    MDL>Phil Pendlebury, David Floyd, Jan Truijens, Stevie, Rustam, Pal Svennevig,  SLL, Jake, Paul Woodlock, Brian Hendrickson, Marcus Tettmar, JRL
    RDA>ChooserDialog
  ENDIF
  IF>ress=60
    Executefile>http://www.pendlebury.biz
    RDA>ChooserDialog
  ENDIF
  //
  //
  Wait>0.001
GOTO>ChooseLoop
//
Label>continue
CloseDialog>ChooserDialog
//
Let>ini_section=1
//
Label>ini_loop
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,server_name,ini_part
If>ini_part=ftp_site
  GOTO>readallinfo
ENDIF
Let>ini_section=ini_section+1
GOTO>ini_loop
//
Label>readallinfo
ReadIniFile>%FTPINIFILE%\ftp.ini,defaults,def_hotkey,defhotkey
ReadIniFile>%FTPINIFILE%\ftp.ini,defaults,def_log,deflog
ReadIniFile>%FTPINIFILE%\ftp.ini,defaults,def_capture,defcapture
ReadIniFile>%FTPINIFILE%\ftp.ini,defaults,def_restart,defrestart
//
Let>make_new_entry=0
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,server_name,def_name
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,server_address,def_server
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,remote_path,def_folder
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,online_path,def_http
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,ftp_username,def_username
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,ftp_password,def_password
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,hide_password,def_hide
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,bbcode,def_bb
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,clip,def_clipboard
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,server_port,def_port
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,upload_mode,def_mode
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,passive_mode,def_passive
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,swap_these,def_swap
ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,swap_with,def_with
IF>fromsendto=False
  ReadIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,last_path,def_file
ENDIF

//
IF>def_bb=IMG
  Let>bb_radio=0
ENDIF
IF>def_bb=URL
  Let>bb_radio=1
ENDIF
IF>def_bb=NONE
  Let>bb_radio=2
ENDIF
//
IF>def_clipboard=FULL
  Let>clip_radio=0
ENDIF
IF>def_clipboard=FTP
  Let>clip_radio=1
ENDIF
IF>def_clipboard=HTTP
  Let>clip_radio=2
ENDIF
//
GOTO>skipnew
//
Label>makenew
CloseDialog>ChooserDialog
Let>make_new_entry=1
Let>def_name=
Let>def_server=
Let>def_folder=
Let>def_http=
Let>def_username=
Let>def_password=
Let>def_hide=
Let>bb_radio=0
Let>clip_radio=0
Let>def_port=21
Let>def_mode=I
Let>def_passive=1
Label>skipnew
//
Dialog>FTPDialog
   Caption=FTP Uploader
   Width=391
   Height=474
   Top=CENTER
   Left=CENTER
   Max=0
   Min=0
   Close=0
   Resize=0
   Label=FTP Uploader,8,8,true
   Edit=msEdit7,88,39,233,def_name
   Edit=msEdit1,88,69,233,def_server
   Edit=msEdit2,88,99,233,def_folder
   Edit=msEdit3,88,129,233,def_http
   Edit=msEdit4,88,159,233,def_username
   Edit=msEdit5,88,189,233,*TYPE HERE TO CHANGE*
   Edit=msEdit6,88,219,233,def_file
   Edit=msEdit8,88,249,145,def_swap
   Edit=msEdit9,272,249,49,def_with
   Edit=msEdit10,272,279,49,defhotkey
   RadioGroup=msRadioGroup1,BBCode,8,281,73,80,IMG%CRLF%URL%CRLF%NONE,bb_radio
   RadioGroup=msRadioGroup2,Clipboard,88,280,73,81,FULL%CRLF%FTP%CRLF%HTTP,clip_radio
   CheckBox=msCheckBox1,Write Log File,232,304,102,deflog
   CheckBox=msCheckBox2,Capture URL to Log File,232,322,145,defcapture
   CheckBox=msCheckBox3,Restart After Upload,232,340,122,defrestart
   Label=Name:,8,42,true
   Label=FTP Server:,8,72,true
   Label=FTP Path:,8,102,true
   Label=HTTP Path:,8,132,true
   Label=FTP Username:,8,162,true
   Label=FTP Password:,8,192,true
   Label=Upload File:,8,222,true
   Label=Browser HotKey:,185,282,true
   Button=GO,224,376,153,41,4,,Go for it!
   Button=QUIT,8,376,153,41,3,,Quit Now!
   Button=WRITE,328,38,49,172,5,,Write current config to ini file
   Button=Browse,328,218,49,23,0,,Browse for file to upload
   Label=Replace:,8,252,true
   Label=With:,240,252,true
   FileBrowse=Browse,msEdit6,,open,%def_file%
   MainMenu=Menu,About(30),Manual(40),Developers(50),WWW(60),Quit(3)
   MainMenu=Choose Site,About(30),Manual(40),Developers(50),WWW(60),Quit(3)
EndDialog>FTPDialog

//
Label>ShowFTP
Show>FTPDialog
Label>DialogLoop
  GetDialogAction>FTPDialog,res
  //
  Let>name=%FTPDialog.msEdit7%
  Let>server=%FTPDialog.msEdit1%
  Let>folder=%FTPDialog.msEdit2%
  Let>httpad=%FTPDialog.msEdit3%
  Let>username=%FTPDialog.msEdit4%
  Let>password=%def_password%
  Let>newpassword=%FTPDialog.msEdit5%
  Let>filename=%FTPDialog.msEdit6%
  Let>bbcodetype=%FTPDialog.msRadioGroup1%
  Let>cliptype=%FTPDialog.msRadioGroup2%
  Let>logfileon=%FTPDialog.msCheckBox1%
  Let>urltolog=%FTPDialog.msCheckBox2%
  Let>restart_after=%FTPDialog.msCheckBox3%
  Let>notallowed=%FTPDialog.msEdit8%
  Let>replacewith=%FTPDialog.msEdit9%
  Let>hotkey=%FTPDialog.msEdit10%
  //
  IF>%newpassword%<>*TYPE HERE TO CHANGE*
    Let>password=%newpassword%
  ENDIF
  //
  /////////////////////////////////////////
  IF>fromsendto=False
    Let>FTPDialog.msEdit6.fbinit=%def_file%
    rda>FTPDialog
  ELSE
    IF>webupload=False
      Separate>%def_file%,\,fchunks
      Let>def_actual=fchunks_%fchunks_count%
      StringReplace>%def_file%,%def_actual%,,def_path
      Let>FTPDialog.msEdit6.fbinit=%def_path%
      rda>FTPDialog
    ENDIF
  ENDIF
  //
  IF>res=4,doitnow
  IF>res=3,Exit
  IF>res=5,writeini
  IF>res=30
    MDL>FTP Uploader by Phil Pendlebury%CRLF%%CRLF%%version%
    RDA>FTPDialog
  ENDIF
  IF>res=40
    Executefile>%FTPINIFILE%\ftpuploader.chm
    RDA>FTPDialog
  ENDIF
  IF>res=50
    MDL>Phil Pendlebury, David Floyd, Jan Truijens, Stevie, Rustam, Pal Svennevig,  SLL, Jake, Paul Woodlock, Brian Hendrickson, Marcus Tettmar, JRL
    RDA>FTPDialog
  ENDIF
  IF>res=60
    Executefile>http://www.pendlebury.biz
    RDA>FTPDialog
  ENDIF
  /////////////////////////////////////////
  Wait>0.001
GOTO>DialogLoop
//
Label>doitnow
CloseDialog>FTPDialog
//
IF>%urltolog%=True
    Let>logfileon=True
    StringReplace>%hotkey%, ,,hotkey
    Separate>%hotkey%,+,hotkey_arr
    Let>hkey_1=hotkey_arr_1
    Let>hkey_U=hotkey_arr_2
    Let>hkey_2={lower(%hkey_U%)}
ENDIF
//
MidStr>%filename%,1,7,html_string
  IF>%html_string%=http://
    Let>webupload=True
    Separate>%filename%,/,httpchunks
    Let>temp_name=httpchunks_%httpchunks_count%
    HTTPRequest>%filename%,%FTPINIFILE%\%temp_name%,GET,,,,,,
    Let>actualfile=%temp_name%
    Let>filename=%FTPINIFILE%\%temp_name%
  ELSE
    Let>webupload=False
    StringReplace>%filename%,/,\,filename
    Separate>%filename%,\,chunks
    Let>actualfile=chunks_%chunks_count%
  ENDIF
//
IF>{(%actualfile%="") OR (%filename%="")}
  MessageModal>NO FILE SELECTED!%CRLF%%CRLF%Please select a file using the Browse button or paste a URL into the Upload File area.%CRLF%%CRLF%Press OK to continue.
  GOTO>ShowFTP
ENDIF
//
Length>%notallowed%,length_na
IF>%length_na%>0
  GOSUB>namecheck
ENDIF
//
IF>def_passive=0
  Let>FTP_PASSIVE=0
ELSE
  Let>FTP_PASSIVE=1
ENDIF
//
Msg>Uploading to FTP
//
FTPPutFile>%server%,%username%,%password%,%def_port%,%filename%,%folder%,%actualfile%,%def_mode%
IF>%FTP_RESULT%=Success
  // Do nothing
ELSE
  IF>%FTP_RESULT%=-
    MDL>Server could not be contacted. Please check the FTP server address.
    RDA>FTPDialog
    GOTO>ShowFTP
  ENDIF
  MDL>%FTP_RESULT%
  RDA>FTPDialog
  GOTO>ShowFTP
ENDIF
//
IF>webupload=True
  StringReplace>%FTPDIALOG.MSEDIT6%,%actualfile%,,used_path
  DeleteFile>%filename%
ELSE
  IF>fromsendto=True
    Let>used_path=%def_path%
  ELSE
    StringReplace>%filename%,%actualfile%,,used_path
  ENDIF
ENDIF
//////////////////////////////////////////////////////////////////////////////
EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,last_path,%used_path%
//
GetDate>is_date
GetTime>is_time
//
IF>cliptype=FULL
  Let>full_ftp_location=%username%:%password%@%server%/%folder%/%actualfile%
  Let>clip_ftp_location=%username%:%password%@%server%/%folder%/%actualfile%
  StringReplace>full_ftp_location,//,/,full_ftp_location
  StringReplace>clip_ftp_location,//,/,clip_ftp_location
  Let>full_ftp_location=ftp://%full_ftp_location%
  Let>clip_ftp_location=ftp://%clip_ftp_location%
ENDIF
IF>cliptype=FTP
  Let>full_ftp_location=%server%/%folder%/%actualfile%
  Let>clip_ftp_location=%server%/%folder%/%actualfile%
  StringReplace>full_ftp_location,//,/,full_ftp_location
  StringReplace>clip_ftp_location,//,/,clip_ftp_location
  Let>full_ftp_location=ftp://%full_ftp_location%
  Let>clip_ftp_location=ftp://%clip_ftp_location%
ENDIF
IF>cliptype=HTTP
  Let>full_ftp_location=%server%/%folder%/%actualfile%
  Let>clip_ftp_location=%httpad%/%actualfile%
  StringReplace>full_ftp_location,//,/,full_ftp_location
  StringReplace>clip_ftp_location,//,/,clip_ftp_location
  Let>full_ftp_location=ftp://%full_ftp_location%
  Let>clip_ftp_location=http://%clip_ftp_location%
ENDIF
//
IF>bbcodetype=IMG
  Let>clip_ftp_location=[img]%clip_ftp_location%[/img]
ENDIF
IF>bbcodetype=URL
  Let>clip_ftp_location=[URL]%clip_ftp_location%[/url]
ENDIF
IF>bbcodetype=NONE
  // Left intentionally blank!
ENDIF
PutClipBoard>%clip_ftp_location%
//
MessageModal>File: %actualfile% has been uploaded%CRLF%%CRLF%The info has been copied to your clipboard%CRLF%%CRLF%Now simply paste to your desired location if required.
/////////////////
IF>logfileon=True
  WriteLn>%FTPINIFILE%\%server%.txt,lineresult,%CRLF%%name% - %is_date% %is_time%%CRLF%File: %actualfile%%CRLF%Written to: %full_ftp_location%%CRLF%Clipboard: %clip_ftp_location%
ENDIF
IF>urltolog=True
  MessageModal>About to copy and write current URL to the log file%CRLF%%CRLF%Do not continue until you have submitted your post and the web page has re-loaded%CRLF%%CRLF%Web browser must have focus for this operation. You can be sure it has focus by clicking on the browser window%CRLF%%CRLF%Press OK to capture the current URL in 5 seconds.
  Wait>5
  Press %hkey_1%
  Wait>0.1
  Send>%hkey_2%
  Release %hkey_1%
  Wait>1
  Press CTRL
  Wait>0.1
  Send>c
  Release CTRL
  Wait>1
  GetClipBoard>url_copy
  WriteLn>%FTPINIFILE%\%server%.txt,lineresult,Posted to this URL: %url_copy%
  MDL>URL %url_copy% Info written to log file.%CRLF%%CRLF%Thank you for using FTP Uploader.
ENDIF
/////////////////
EditIniFile>%FTPINIFILE%\ftp.ini,defaults,def_hotkey,%hotkey%
EditIniFile>%FTPINIFILE%\ftp.ini,defaults,def_log,%logfileon%
EditIniFile>%FTPINIFILE%\ftp.ini,defaults,def_capture,%urltolog%
EditIniFile>%FTPINIFILE%\ftp.ini,defaults,def_restart,%restart_after%
/////////////////
IF>restart_after=True
  CloseDialog>FTPDialog
  GOTO>ShowFTP
ELSE
  GOTO>Exit
ENDIF
//
//
// Write info to new section of ini  file
Label>writeini
CloseDialog>FTPDialog
//
IF>make_new_entry=0
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,server_name,%name%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,server_address,%server%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,remote_path,%folder%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,online_path,%httpad%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,ftp_username,%username%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,ftp_password,%password%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,bbcode,%bbcodetype%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,clip,%cliptype%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,swap_these,%notallowed%
  EditIniFile>%FTPINIFILE%\ftp.ini,%ini_section%,swap_with,%replacewith%
ENDIF
//
IF>make_new_entry=1
  WriteLn>%FTPINIFILE%\ftp.ini,q,
  WriteLn>%FTPINIFILE%\ftp.ini,q,[%info_count%]
  WriteLn>%FTPINIFILE%\ftp.ini,q,server_name=%name%
  WriteLn>%FTPINIFILE%\ftp.ini,q,server_address=%server%
  WriteLn>%FTPINIFILE%\ftp.ini,q,remote_path=%folder%
  WriteLn>%FTPINIFILE%\ftp.ini,q,online_path=%httpad%
  WriteLn>%FTPINIFILE%\ftp.ini,q,ftp_username=%username%
  WriteLn>%FTPINIFILE%\ftp.ini,q,ftp_password=%newpassword%
  WriteLn>%FTPINIFILE%\ftp.ini,q,bbcode=%bbcodetype%
  WriteLn>%FTPINIFILE%\ftp.ini,q,clip=%cliptype%
  WriteLn>%FTPINIFILE%\ftp.ini,q,server_port=21
  WriteLn>%FTPINIFILE%\ftp.ini,q,upload_mode=I
  WriteLn>%FTPINIFILE%\ftp.ini,q,passive_mode=1
  WriteLn>%FTPINIFILE%\ftp.ini,q,swap_these=()<>\/-:*?" |
  WriteLn>%FTPINIFILE%\ftp.ini,q,swap-with=_
  WriteLn>%FTPINIFILE%\ftp.ini,q,
ENDIF
//
MessageModal>INI File written. Hit OK to continue.
GOTO>ShowFTP
//
SRT>namecheck
   // ENTER DISALLOWED CHARACTERS
  Length>%notallowed%,naloop
  // CHECK TO SEE IF DISALLOWED CHARS ARE IN FILENAME
  Let>rep=1
  REPEAT>rep
  MidStr>%notallowed%,rep,1,isitthere

  // FIND DISALLOWED AND IF ITS THERE REPLACE IT WITH UNDERSCORE
  StringReplace>%actualfile%,isitthere,%replacewith%,actualfile

  Let>rep=rep+1
  UNTIL>rep>naloop
End>namecheck

Label>Exit
Exit>
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts