FtpScript

Discuss and share scripts and script files...
Post Reply
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

FtpScript

Post by serendipity »

Simple ftp script (using windows ftp command) to upload selected files.
Download:
FtpScript.xys
(1.69 KiB) Downloaded 314 times

Code: Select all

//FtpScript
//A simple ftp script to upload selected file to server (Uses Windows' native ftp command)

//Your ftp server address
   $ftpaddress = "YourDomain.com";

//Directory to upload files to
   $dir= input ("Directory to upload to", "Enter directory name <crlf>Leave empty to upload files to root ($ftpaddress/)", "");
   $dir= "/$dir";

//Your Server login or Username
   $username = "username"; 
//Enter password
   $pass= input ("Enter password", "Address = $ftpaddress$dir <crlf>Username = $username", "password", s);

//Focus list
 focus;

//Get selected file info
   $files= getinfo ("SelectedItemsPathNames", """ """);

//remove extra "
   substr $files, $files, 0,-1;

//Add trailing "
   $files="""$files";

//Command for batch file to be run in cmd
 $ftpinfo= <<<FOO
@echo off
echo open $ftpaddress>> "<xypath>\Scripts\ftpcmd.dat"
echo $username>> "<xypath>\Scripts\ftpcmd.dat"
echo $pass>> "<xypath>\Scripts\ftpcmd.dat"
echo cd $dir>> "<xypath>\Scripts\ftpcmd.dat"
echo mput $files>> "<xypath>\Scripts\ftpcmd.dat"
echo bye>> "<xypath>\Scripts\ftpcmd.dat"
ftp -i -s:"<xypath>\Scripts\ftpcmd.dat" >>"<xypath>\Scripts\FtpScript.log"
del "<xypath>\Scripts\ftpcmd.dat"
FOO;

//Write above commands to batch file
   writefile ("<xypath>\Scripts\FtpScript_upload.bat", $ftpinfo);

//Run batch file
   run """<xypath>\Scripts\FtpScript_upload.bat""",, 1;

//Delete batch file (it has your password)
   delete 0, 0, "<xypath>\Scripts\FtpScript_upload.bat";

//Go to log file (has details about your recent upload)
   goto (confirm ("Upload log at <xypath>\Scripts\FtpScript.log<br><br>OK=Goto log <br>Cancel=stay here") == 1 ? "<xypath>\Scripts\FtpScript.log": "<curpath>");

admin
Site Admin
Posts: 65269
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: FtpScript

Post by admin »

Interesting! :) One thing: It should be <xydata>, not <xypath>, to find the scripts folder in every configuration. I would use a variable:

Code: Select all

...
//Script path   
   $path = "<xydata>\Scripts";

//Command for batch file to be run in cmd
 $ftpinfo= <<<FOO
@echo off
echo open $ftpaddress>> "$path\ftpcmd.dat"
echo $username>> "$path\ftpcmd.dat"
etc.
...

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: FtpScript

Post by serendipity »

admin wrote:Interesting! :) One thing: It should be <xydata>, not <xypath>, to find the scripts folder in every configuration. I would use a variable:

Code: Select all

...
//Script path   
   $path = "<xydata>\Scripts";

//Command for batch file to be run in cmd
 $ftpinfo= <<<FOO
@echo off
echo open $ftpaddress>> "$path\ftpcmd.dat"
echo $username>> "$path\ftpcmd.dat"
etc.
...
Thanks Don, I did not bother to clean-up my old script. Now I will, :D .
FtpScript.xys
(1.6 KiB) Downloaded 281 times

Code: Select all

//FtpScript
//A simple ftp script to upload selected file to server (Uses Windows' native ftp command)

//Your ftp server address
   $ftpaddress = "YourDomain.com";

//Directory to upload files to
   $dir= input ("Directory to upload to", "Enter directory name <crlf>Leave empty to upload files to root ($ftpaddress/)", "");
   $dir= "/$dir";

//Your Server login or Username
   $username = "username"; 
//Enter password
   $pass= input ("Enter password", "Address = $ftpaddress$dir <crlf>Username = $username", "password", s);

//Focus list
 focus;

//Get selected file info
   $files= getinfo ("SelectedItemsPathNames", """ """);

//remove extra "
   substr $files, $files, 0,-1;

//Add trailing "
   $files="""$files";

//Path to scripts folder
  $path="<xydata>\Scripts";

//Command for batch file to be run in cmd
 $ftpinfo= <<<FOO
@echo off
echo open $ftpaddress>> "$path\ftpcmd.dat"
echo $username>> "$path\ftpcmd.dat"
echo $pass>> "$path\ftpcmd.dat"
echo cd $dir>> "$path\ftpcmd.dat"
echo mput $files>> "$path\ftpcmd.dat"
echo bye>> "$path\ftpcmd.dat"
ftp -i -s:"$path\ftpcmd.dat" >>"$path\FtpScript.log"
del "$path\ftpcmd.dat"
FOO;

//Write above commands to batch file
   writefile ("$path\FtpScript_upload.bat", $ftpinfo);

//Run batch file
   run """$path\FtpScript_upload.bat""",, 1;

//Delete batch file (it has your password)
   delete 0, 0, "$path\FtpScript_upload.bat";

//Go to log file (has details about your recent upload)
   goto (confirm ("Upload log at $path\FtpScript.log<br><br>OK=Goto log <br>Cancel=stay here") == 1 ? "$path\FtpScript.log": "<curpath>");

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: FtpScript

Post by serendipity »

UPDATE: the attached script had a missing ";" on line 29. It only worked if you copy/pasted the code below. Now both attached and pasted script are the same.

Post Reply