Jump to content
Sign in to follow this  
JamesBand

FTP Upload with Scriptmaster!

Recommended Posts

Requirements:

ScriptMaster for FMP (AWESOME!)

Download simpleftp.jar (and put it somewhere you can find it later, like the Groovy lib folder if you have Groovy installed ;) )

Should be in a startup script: (should only be loaded once per FM session, dunno if loading more times will break it or not.)


SMLoadJar ( "file://C:/Program Files/Groovy/lib/simpleftp.jar" )





Example code: (shamelessly ripped from the SimpleFTP website)



EvaluateGroovy("

	

	import org.jibble.simpleftp.*;

	

	def ftp = new SimpleFTP(); //modified this line

	    

	// Connect to an FTP server on port 21.

	ftp.connect("ftp.somewhere.net", 21, "username", "password");

	

	// Set binary mode.

	ftp.bin();

	

	// Change to a new working directory on the FTP server.

	//ftp.cwd("web");

	

	// Upload some files.

	ftp.stor(new File("file://C:/Program Files/Groovy/lib/simpleftp.jar"));

	//ftp.stor(new File("comicbot-latest.png"));

	

	// You can also upload from an InputStream, e.g.

	// Well... I haven't tested this in ScriptMaster and I cannot think

	// of a reason to use it from Filemaker... But, here is is anyway.

	//ftp.stor(new FileInputStream(new File("test.png")), "test.png");

	//ftp.stor(someSocket.getInputStream(), "blah.dat");

	

	// Quit from the FTP server.

	ftp.disconnect();

	

")

Edited by Guest

Share this post


Link to post
Share on other sites

Hello,

I am testing this function and I receive the following result:

org.jibble.simpleftp.SimpleFTP@12368df

Do you know what it means?

Thank You...

Share this post


Link to post
Share on other sites

Yeah... The newer versions of ScriptMaster don't seem to be compatible with the SimpleFTP.jar.

My recommendation is to spring for the 360Works FTP plugin.

Share this post


Link to post
Share on other sites

Hello there,

I'm using the Jakarta Commons Net-Library from apache.org for FTP.

It works very nice under FM Pro 10 (Win7).

Don't know about different versions or platforms.

To use it, just download the Library and add commons-net-ftp-2.0.jar to the List of Jar-Files and connect like this:


ftp = new FTPClient();

ftp.connect( "ftp.yourhost.com" );

ftp.login( "username", "password" );

You can get the download, further details and examples, as well as a complete javadoc on the following site:

http://commons.apache.org/net/

This library is able to deal with several other protocols, e.g. POP3 and SMTP. I haven't tested these features yet though.

Regards,

Lumpi23

Share this post


Link to post
Share on other sites

I've been using this as well for some time.

where FM parameters ftp_hostname, ftp_username, ftp_password are the hostname, username, and password. Local filename is local path e.g. C:text.dat, remote_directorypath is e.g. /httpdocs, remote_filename is the remote filename, and mode_bin_or_text is the mode, bin or text for binary or text. I also set two timeouts to 20 seconds so it won't hang (20,000 msec) per below.

Presumably, you could also run a java program from FM, by running javac followed by java (no SM plugin required), but the plugin certainly simplifies passing parameters and retrieving results from the JVM.

One thing I would like to do with this plugin, is figure out how to use jniwrapper, winapi, etc to get a handle on, and attach to, a webviewer control to permit it to be automated.

// NOTE: This uses http://commons.apache.org/net/

// FAQ for commons here: http://wiki.apache.org/jakarta-commons/Net/FrequentlyAskedQuestions



import org.apache.commons.net.ftp.FTPClient;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.io.PrintWriter;

import org.apache.commons.net.ftp.FTP;

import org.apache.commons.net.ftp.FTPClient;

import org.apache.commons.net.ftp.FTPConnectionClosedException;

import org.apache.commons.net.ftp.FTPReply;



try {

FTPClient connection = new FTPClient();

connection.connect(ftp_hostname);            

boolean logged = connection.login(ftp_username, ftp_password);    

if (logged) 



{

connection.setSoTimeout(20000);

connection.setDataTimeout(20000);



if (mode_bin_or_text=="bin")

{

  connection.setFileType(connection.BINARY_FILE_TYPE);

}



if (mode_bin_or_text=="text")

{

  connection.setFileType(connection.ASCII_FILE_TYPE);

}





    connection.changeWorkingDirectory(remote_directorypath);

connection.enterLocalPassiveMode();

           InputStream input;



            input = new FileInputStream(local_filename);



               connection.storeFile(remote_filename, input);



                input.close();



    connection.logout();





connection.disconnect();



return"Upload Succeeded";

}

else

return"Error while connecting to FTP...............";

} catch (Exception e) {

return e;

}

Share this post


Link to post
Share on other sites

I'm trying this code but it doesn't work.

After loaded jar files, I've registered this function:

RegisterGroovy( "FTPSendFile ( ftp_hostname; ftp_username ; ftp_password ; local_filename ; remote_directorypath ; remote_filename ; mode_bin_or_text )"; "

FTPClient connection = new FTPClient();

connection.connect(ftp_hostname);            

boolean logged = connection.login(ftp_username, ftp_password);



if (logged)

{

connection.setSoTimeout(20000);

connection.setDataTimeout(20000);



if (mode_bin_or_text=='bin') { connection.setFileType(connection.BINARY_FILE_TYPE); }

if (mode_bin_or_text=='text') { connection.setFileType(connection.ASCII_FILE_TYPE); }



connection.changeWorkingDirectory(remote_directorypath);

connection.enterLocalPassiveMode();



InputStream input;

input = new FileInputStream(local_filename);

connection.storeFile(remote_filename, input);

input.close();

connection.logout();

connection.disconnect();



// Succeded

return '1';

} else return 'ERROR';

" )




And then called like:


FTPSendFile( "";"testuser";"testpass"; $$MyFile ; "/" ; "example.pdf" ; "bin" )

It returns a blank value, and nothing arrives to the server.

Any help?

Share this post


Link to post
Share on other sites

Added import classes at the beginning of the script:

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.io.PrintWriter;

import org.apache.commons.net.ftp.FTP;

import org.apache.commons.net.ftp.FTPClient;

import org.apache.commons.net.ftp.FTPConnectionClosedException;

import org.apache.commons.net.ftp.FTPReply;

And now returns a '?' value.

Any help?

Share this post


Link to post
Share on other sites

Finally worked!


RegisterGroovy( "FTPSendFile ( ftp_hostname ; ftp_username ; ftp_password ; local_filename ; remote_directorypath ; remote_filename )"; "



import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import org.apache.commons.net.ftp.*;



try {

FTPClient connection = new FTPClient();

connection.connect(ftp_hostname);            

boolean logged = connection.login(ftp_username, ftp_password);

if (!logged) return "0";



connection.setSoTimeout(20000);

connection.setDataTimeout(20000);

connection.setFileType(connection.BINARY_FILE_TYPE);



connection.changeWorkingDirectory(remote_directorypath);

connection.enterLocalPassiveMode();



InputStream input;

input = new FileInputStream(local_filename);

connection.storeFile(remote_filename, input);

input.close();



return "1";

} catch (Exception e) {

return e;

}

" )

Now I'll try to FTPGetFile...

:

Share this post


Link to post
Share on other sites

FTP get.. doesn't check if the file is actually there but seems to work


// FTPget ( ftp_host ; ftp_user ; ftp_password ; remote_path ; local_path ; fm_file ; mode_bin_or_text )

// 11_01_20 JR

// v1

// downloads file from fTP site, returns true if successful or false or error



import org.apache.commons.net.ftp.*



_sep = System.getProperty("file.separator")

try {

	conn = new FTPClient()

	conn.connect(ftp_host)

	boolean logged = conn.login(ftp_user, ftp_password)

	if(logged) {

		conn.setSoTimeout(20000)

		conn.setDataTimeout(20000)

		conn.changeWorkingDirectory(remote_path)

		conn.enterLocalPassiveMode()

		fos = new FileOutputStream(local_path + _sep + fm_file)

		conn.retrieveFile(fm_file, fos)

		fos.close()

		conn.logout()

		conn.disconnect()

		//return"Download Succeeded.."

		return true

	} else {

		//return"Error while connecting to FTP..............."

		return false

	} // end if

}

catch(Exception e) {

	return e

}

Share this post


Link to post
Share on other sites

Hello,

Looking for a script to upload files on FTP I found the Xavier 782's script. After loadinf the classes requested I've always an error you can see on the attachment
Thanks for your help !

Noël

post-71369-0-66749600-1382981420_thumb.p

Share this post


Link to post
Share on other sites

Its a copy and paste from the internet problem...

Somewhere on the last line is something which looks like a space but isn't

 

Try deleting line 30 and typing it by hand..

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.