FTP with edtftpj
From Processing
| Versions: | 1.0+ |
| Contributors: | markhill |
| Started: | 2006-03-21 |
FTP can be easily integrated into your sketches using edtftpj.
This snippet is the Processing equivalent of the out-of-the-box demo supplied with edtftpj. Working with threads means you can have a ftp system running alongside your sketch to avoid having to wait for ftp tasks to complete.
Source Code
/** * ftp taken from http://wiki.processing.org/index.php?title=FTP_with_edtftpj * @author Mark Hill */ FTPClient ftp; // Populate these variables with the necessary info. String host = ""; String username = ""; String password = ""; String remotePath = "" String localPath = ""; void setup () { try { // set up client ftp = new FTPClient(); ftp.setRemoteHost(host); FTPMessageCollector listener = new FTPMessageCollector(); ftp.setMessageListener(listener); // connect println ("Connecting"); ftp.connect(); // login println ("Logging in"); ftp.login(username, password); // set up passive ASCII transfers println ("Setting up passive, ASCII transfers"); ftp.setConnectMode(FTPConnectMode.PASV); ftp.setType(FTPTransferType.ASCII); // get directory and print it to console println ("Directory before put:"); String[] files = ftp.dir(".", true); for (int i = 0; i < files.length; i++) println (files[i]); // copy file to server println ("Putting file"); ftp.put("/localPath/test.txt", "/remotePath/test.txt"); // get directory and print it to console println ("Directory after put"); files = ftp.dir(".", true); for (int i = 0; i < files.length; i++) println (files[i]); // copy file from server println ("Getting file"); ftp.get("/localPath/test.txt" + ".copy", "/remotePath/test.txt"); // delete file from server println ("Deleting file"); ftp.delete("/remotePath/test.txt"); // get directory and print it to console println ("Directory after delete"); files = ftp.dir("", true); for (int i = 0; i < files.length; i++) println (files[i]); // Shut down client println ("Quitting client"); ftp.quit(); String messages = listener.getLog(); println ("Listener log:"); println(messages); println ("Test complete"); } catch (Exception e) { println ("Demo failed"); } }