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.

Featured Replies

Just updated my ftp functions to add some functionality for a job.

Some of the techniques might prove useful if you want to dig into them

Uses the Commons-Net-3.2 jar but should also work with Commons-Net-Ftp-2.0

First also needs Commons-io jar

 

List image files:

// FTPlist ( ftp_host ; ftp_user ; ftp_password ; remote_path )
// 13_05_22 JR
// v1.0
// returns date sorted list of tab separated file entries
// date, time, size, name

import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTPFile
import org.apache.commons.io.FileUtils
import java.text.SimpleDateFormat

try{
	new FTPClient().with{
		connect ftp_host
		login ftp_user, ftp_password
		names = listFiles(remote_path)
		logout()
		disconnect()
		} //end with
} catch (e) {
	return e
} //end try

sdf = new SimpleDateFormat("dd/MM/yyyytHH:mm")
sdg = new SimpleDateFormat("yyyy/MM/dd")
sdh = new SimpleDateFormat("HH:mm")
list = []
filenames = []
TAB = 't'

names.each{
	if(it.getType() == FTPFile.FILE_TYPE){
		tx = it.getTimestamp().getTime()
		list.add(new Expando(date:sdg.format(tx), time:sdh.format(tx), fmdate:sdf.format(tx), name:it.getName(), size:FileUtils.byteCountToDisplaySize(it.getSize())))
	} //end if
} //end each

// SORT by date, then time, then name
ls = list.sort{x,y -> x.date<=>y.date ?: x.time<=>y.time ?: x.name<=>y.name}
ls.each{
	filenames += it.fmdate + TAB + it.size + TAB + it.name
} //end each

return filenames ?: false

Get specific file

// FTPgetFile ( ftp_host ; ftp_user ; ftp_password ; remote_path ; local_path ; fm_file )
// 13_05_22 JR
// v1.0
// downloads file from fTP site, returns true if successful or false or error

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

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

try{
	new FTPClient().with {
		connect ftp_host
		enterLocalPassiveMode()
		login ftp_user, ftp_password
		changeWorkingDirectory remote_path
		setFileType(FTP.BINARY_FILE_TYPE)
		incomingFile = new File(local_path + SEP + fm_file)
		incomingFile.withOutputStream { ostream -> 
			retrieveFile fm_file, ostream 
		} //end stream
                logout()
		disconnect()
	} //end with
} catch (e) {
	return e
} //end try

if (!new File(local_path + SEP + fm_file).size()){
	return false
}
return true

Delete specific file

// FTPdeleteImage ( ftp_host ; ftp_user ; ftp_password ; remote_path ; fm_file )
// 13_05_22 JR
// v1.0
// deletes file from fTP site, returns true if successful or false or error

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

try{
	new FTPClient().with {
		connect ftp_host
		enterLocalPassiveMode()
		login ftp_user, ftp_password
		changeWorkingDirectory remote_path
		deleteFile fm_file
                logout()
		disconnect()
	} //end with
} catch (e) {
	return e
} //end try

return true
  • 5 months later...

Hello,

I just found that thread and your functions. You call the first one "List image file" ; I tried it and on a directory I got

 

28/10/2013    16:32    0 bytes    bof
28/10/2013    17:01    25 KB    130.gif
30/10/2013    13:52    74 KB    Afonso_aline.pdf
30/10/2013    13:52    76 KB    Auroire_Christine.pdf
30/10/2013    14:34    6 KB    test.txt

I thought it listed all file types, but in another directory I had flv files the function returns 0.

I'd like to get all files, and even in sub-directories. What must I modify ?

Thanks

Noël

 

Sorry for the noise : I just find that the path to the remote directory is sensible to the uppercase or lowercase !

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.