FTPUpload.frink

View or download FTPUpload.frink in plain text format


/** This file gives an example of uploading a file to an FTP server.  It is
    based on the solution at:  https://stackoverflow.com/a/17454840

    Frink internally has classes that will allow copying from an InputStream
    to an OutputStream which will simplify this code in the future. */

FTPUpload[urlString, filename] :=
{
   url = newJava["java.net.URL", urlString]
   conn  = url.openConnection[]
   outputStream = conn.getOutputStream[]
   inputStream = newJava["java.io.FileInputStream", filename]

   buffer = newJavaArray["byte", 16384]
   while ((bytesRead = inputStream.read[buffer]) != -1)
      outputStream.write[buffer, 0, bytesRead]

   inputStream.close[]
   outputStream.close[]
}

// Example of creating a URL to upload to (you'll want to change this)
username = URLEncode["myusername", "UTF-8"]
password = URLEncode["mypassword", "UTF-8"]
hostname = "ftp.whereever.com"
localFilename = "FTPUpload.frink"   // Uploading self
targetFilename = localFilename   // Use same remote filename in root of server
FTPUpload["ftp://$username:$password@$hostname/$targetFilename", localFilename]


View or download FTPUpload.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 17590 days, 6 hours, 52 minutes ago.