PRODUCT






Home









Free Download








Installation Instructions





FAQ





FAQ








Ask A Question





LEARN SCRIPTING





Overview








Lesson 1








2


3


4


5








Exam





SAMPLE SCRIPTS





Computer








Internet








Administrators








Developers








Data








Miscellaneous





HELP / DOCUMENTATION





Commands








Automated Internet








Automated Editors








Sample Scripts








Precompiled Functions








System Features






  Help Page - SS_FTPUpload

( Some help pages may not display correctly in html because those help pages may have sample code
in them, part of which may be mis-interpreted as html tags.

All help pages, including this help page, are available in biterScripting with the help command. )




Sample Script SS_FTPUpload Purpose Copies an entire directory structure (including all files within it) from local computer to a remote FTP server. Source Code ##################################################################### # SCRIPT: SS_FTPUpload.txt # # This script uploads an entire directory structure to an FTP server. # It does this for all files at various levels within a local directory. # The local directory is specified with the input argument $localpath. # The corresponding remote directory is specified with the input argument # $remotepath. # # The script identifies files as either ASCII or Binary using their extensions # and uploads the files in appropriate transfer mode. # # The script takes the following input arguments. # # ftpserver - name of the ftp server # # ftplogin - login id for the ftp session # # ftppassword - password for the ftp session # # localpath - path to the top folder of local files to upload # Must be specified with full path, starting with / or C:/. # # remotepath - path to the remote folder on the FTP server into which files will be uploaded. # Must be specified with full path, starting with / . # Leave remotepath empty if the remote path is same as the default directory # for the specified ftp login id. # # Download this script into directory C:/Scripts to a file named sS_FTPUpload.txt # # Let's say that you have all your web pages in a directory "/mywebsite". You want to upload # all pages into remote folder "/pages" on FTP server "ftp.mycompany.com". You want to use # the login id of "me" and the password of "my password". # # In that case, invoke biterScripting Interactive and type the following # on the command line. # # script "C:/Scripts/SS_FTPUpload.txt" ftpserver("ftp.mycompany.com") ftplogin("me") # ftppassword("my password") localpath("/mywebsite") remotepath("/pages") # # The above needs to be entered all on one command line. # # The script will replicate the entire directory structure at "/mywebsite" from local computer # into directory "/pages" on the remote FTP server. # All files will be copied into appropriate directories and with appropriate transfer mode. # The login "me" needs to have appropriate access permissions on the FTP server. # # The script does not change the files on the local computer. If files already exist on # the FTP server, they will be overwritten. If files do not exist on the FTP server, they # will be created. If there are files on the remote FTP server that do not exist on # the local computer, they will be left unchanged. If directories do not exist on the FTP server, # they will be created. # # Any output and errors from the FTP operations will be brought back into this script's # output stream and error stream respectively, which can then be redirected as necessary. # # The speed of the execution of this script depends on the speed of FTP connection, the # response speed of the server, and the size of data being copied. # # The script can also be scheduled to execute periodically by scheduling the following # command line. # # "C:/biterScripting/biterScripting.exe" "C:/Scripts/SS_FTPUpload.txt" ftpserver("ftp.mycompany.com") ftplogin("me") # ftppassword("my password") localpath("/mywebsite") remotepath("/pages") # # If you don't have biterscripting, you can download it from biterScripting.com . # ##################################################################### # Input arguments var str ftpserver, ftplogin, ftppassword, localpath, remotepath # We will define the known ascii and binary file extensions in the following variables. # These will be used later in setting ftp session mode to 'ascii' or 'binary'. # In these lists, each extension starts with a dot and ends with a semicolon. # You can add more extensions to this list, based on the types of files you are uploading. # IT IS IMPORTANT TO NOTE THAT EVEN THE LAST EXTENSION MUST END IN SEMICOLON. var str KNOWN_ASCII_EXTLIST, KNOWN_BIN_EXTLIST set $KNOWN_ASCII_EXTLIST = ".html;.txt;.php;.asp;.pl;.xml;" set $KNOWN_BIN_EXTLIST = ".gif;.jpg;" # We will create the input that will be sent to the ftp server into a temporary file C:/ftpcommands.txt. # We will call this file - the commands file. # First line in the commands file is the login. Second line is the password. echo $ftplogin "\n" $ftppassword > "C:/ftpcommands.txt" # Next command in the commands file is to change remote directory to $remotepath. echo "cd " $remotepath >> "C:/ftpcommands.txt" # Change local directory to $localpath. cd $localpath # Create a list of folders under this directory, including the $localpath itself. var str localdirlist, localdir, remotedir, localfilelist, localfile, filename, fileext echo $localpath > $localdirlist lf -r -n "*" "." ($ftype=="d") >> $localdirlist # Loop thru the $localdirlist. while ($localdirlist <> "") do # Get the next local directory from the list. lex "1" $localdirlist > $localdir # Change local directory to $localdir. echo "lcd \"" $localdir "\"" >> "C:/ftpcommands.txt" # Now, local directory is $localdir. If we replace $localpath by $remotepath in it, # we will get the remote directory. sal -p ("^"+$localpath+"^") $remotepath $localdir > $remotedir # Create the remote directory if it does not already exist. echo "mkdir \"" $remotedir "\"" >> "C:/ftpcommands.txt" # Change remote directory to $remotedir. echo "cd \"" $remotedir "\"" >> "C:/ftpcommands.txt" # Collect a list of files directly under $localdir. lf -n "*" $localdir ($ftype=="f") > $localfilelist # Go thru $localfilelist, one local file at a time. while ($localfilelist <> "") do # Get the next local file. lex "1" $localfilelist > $localfile # We have to decide if this file is an ascii file or a binary file. # For that, we use the file extension. # Known ascii and binary file extensions are defined above in variables # KNOWN_ASCII_EXTLIST and KNOWN_BIN_ESTLIST respectively. # Get the local file's name and extension. stex -p "^/^l[" $localfile > $filename stex -p "[^.^l" $filename > $fileext # Is this file ascii ? if ( { sen -c ("^"+$fileext+";^") $KNOWN_ASCII_EXTLIST } > 0 ) do # This is an ascii file. Upload as ascii. echo "ascii" >> "C:/ftpcommands.txt" echo "put \"" $filename "\"" >> "C:/ftpcommands.txt" done endif # Is this file binary ? if ( { sen -c ("^"+$fileext+";^") $KNOWN_BIN_EXTLIST } > 0 ) do # This is a binary file. Upload as binary. echo "binary" >> "C:/ftpcommands.txt" echo "put \"" $filename "\"" >> "C:/ftpcommands.txt" done endif done done # The last command to send to the ftp server is "bye". echo "bye" >> "C:/ftpcommands.txt" # Start the ftp session and pass it the commands in the commands file. system ("ftp -s:C:/ftpcommands.txt "+$ftpserver) # Delete our tempporary file C:/ftpcommands.txt. system del "C:/ftpcommands.txt" # We are done.

2008-2013, biterScripting.com. All rights reserved.
biterScripting, biterScript, biterBrowser, biterMobile, biterScripting.com, FVA (Forward Variable Assignment) are trademarks of biterScripting.com. Is it biterScripting-compatible ? is a service mark of biterScripting.com. Explorer, Unix, Windows are trademarks, service marks or other forms of intellectual property of their respective owners.