Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

FTP Upload with Scriptmaster!

Featured Replies

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

  • 1 year later...
  • Newbies

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...

  • Author

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.

  • 9 months later...
  • Newbies

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

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;

}

nice ! and thanks !

  • 2 months later...

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?

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?

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...

:

  • 1 month later...

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

}

  • 2 years later...

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

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..

It's what I thinked and tried, without success...

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.