Download presentation
Presentation is loading. Please wait.
Published byJewel Chapman Modified over 8 years ago
1
Lecture 8: FTP into CS System Topics: FTP connect, browse, upload, download Date: Mar 8, 2016
2
Things to Learn (slide only) FTP Overview Using Anonymous FTP on UNC CS Systems Android FTP Client API
3
FTP Overview FTP stands for – File Transfer Protocol Better than HTTP for uploading/downloading multiple large-sized files It is a TCP based service Separate ports for command (21) and data (20) Data ports may be changed (in passive FTP) Directory level control access (username/pass) Less popular, less used, may die soon
4
FTP Passive Mode FTP http://www.slacksite.com/other/ftp.html PASV PORT 2024
5
SSH into UNC CS The File System: To you: /afs/cs.unc.edu/home/ftp To your anonymous friend: / incomingoutgoing you Your Anonymous Friend Will Access This As – ftp.cs.unc.edu Username = anonymous Password = any email address http://cs.unc.edu/help-article/anonymous-ftp/ Upload Download
6
SSH into UNC CS SSH Secure Shell Client classroom.cs.unc.edu CS user/password Useful Commands pwd ls cd mkdir cat touch
7
Uploading Files Uploading files from the phone to a server: Using IP/TCP or IP/UDP Sockets Using HTTP, HTTPS (GET, POST) Using FTP, SFTP / incoming you ftp.cs.unc.edu Username = anonymous Password = any email address Upload
8
Android FTP API Android does not have any! Use 3 rd party Java API: Apache Commons Net https://commons.apache.org/proper/commons-net/ Download: commons-net-3.4.jar https://www.youtube.com/watch?v=tfPgx6c5wgA Add the jar to your Android studio project:
9
Using FTP API to Upload a File Before uploading the file, first copy a file into your phone’s SD card (use ADB or some App) > adb push path/of/computer/file /sdcard/ C:\Users\You\AppData\Local\Android\Sdk\platform-tools The ADB tool can be found at, e.g. Execute this on your computer’s command prompt:
10
Using FTP API to Upload a File Write codes to connect and do stuffs with files (e.g. change directory, browse files, upload) FTPClient ftpClient = new FTPClient(); ftpClient.connect(InetAddress.getByName("ftp.cs.unc.edu")); ftpClient.login("anonymous", "xyz@cs.unc.edu"); ftpClient.changeWorkingDirectory("incoming/nirjon"); FTPFile[] files = ftpClient.listFiles(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); BufferedInputStream buffIn = null; File ff = new File("/sdcard/m.txt"); buffIn = new BufferedInputStream(new FileInputStream(ff)); ftpClient.enterLocalPassiveMode(); ftpClient.storeFile("upload1.txt", buffIn); buffIn.close(); ftpClient.logout(); ftpClient.disconnect(); Tips – use permissions, use AsyncTask
11
Using FTP API to Upload a File Write codes to connect and do stuffs with files (e.g. change directory, browse files, upload) FTPClient ftpClient = new FTPClient(); ftpClient.connect(InetAddress.getByName("ftp.cs.unc.edu")); ftpClient.login("anonymous", "xyz@cs.unc.edu"); ftpClient.changeWorkingDirectory("incoming/nirjon"); FTPFile[] files = ftpClient.listFiles(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); BufferedInputStream buffIn = null; File ff = new File("/sdcard/m.txt"); buffIn = new BufferedInputStream(new FileInputStream(ff)); ftpClient.enterLocalPassiveMode(); ftpClient.storeFile("upload1.txt", buffIn); buffIn.close(); ftpClient.logout(); ftpClient.disconnect(); Tips – use permissions, use AsyncTask
12
Using FTP API to Upload a File Write codes to connect and do stuffs with files (e.g. change directory, browse files, upload) FTPClient ftpClient = new FTPClient(); ftpClient.connect(InetAddress.getByName("ftp.cs.unc.edu")); ftpClient.login("anonymous", "xyz@cs.unc.edu"); ftpClient.changeWorkingDirectory("incoming/nirjon"); FTPFile[] files = ftpClient.listFiles(); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); BufferedInputStream buffIn = null; File ff = new File("/sdcard/m.txt"); buffIn = new BufferedInputStream(new FileInputStream(ff)); ftpClient.enterLocalPassiveMode(); ftpClient.storeFile("upload1.txt", buffIn); buffIn.close(); ftpClient.logout(); ftpClient.disconnect(); Tips – use permissions, use AsyncTask
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.