Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DataBase;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import javax.swing.JOptionPane;
- import StreamBean.UIBean;
- public class FTP{
- private String ftpUrl = "ftp://%s:%s@%s/%s;type=i";
- private final String user = "hakuhun", pass ="jelszo", host = "bakonyigi.heliohost.org";
- private final int port = 21;
- private final int BUFFER_SIZE = 4096;
- private OutputStream os = null;
- private FileInputStream fis = null;
- public FTP(){
- }
- public void uploadVideo(File f){
- ftpUrl = String.format(ftpUrl, user, pass, host, "public_ftp/videos/" + f.getName());
- System.out.println("Upload URL: " + ftpUrl);
- try {
- URL url = new URL(ftpUrl);
- URLConnection con = url.openConnection();
- os = con.getOutputStream();
- fis = new FileInputStream(f);
- byte[] buffer = new byte[BUFFER_SIZE];
- int bytesRead = -1;
- while ((bytesRead = fis.read(buffer)) != -1) {
- os.write(buffer, 0, bytesRead);
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
- }finally{
- try {
- os.close();
- fis.close();
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- }
- }
- public void uploadAvatar(File f){
- File f2 = new UIBean().resizeAvatar(f);
- ftpUrl = String.format(ftpUrl, user, pass, host, "public_ftp/avatars/" + f2.getName());
- System.out.println("Upload URL: " + ftpUrl);
- try {
- URL url = new URL(ftpUrl);
- URLConnection con = url.openConnection();
- os = con.getOutputStream();
- fis = new FileInputStream(f);
- byte[] buffer = new byte[BUFFER_SIZE];
- int bytesRead = -1;
- while ((bytesRead = fis.read(buffer)) != -1) {
- os.write(buffer, 0, bytesRead);
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
- }finally{
- try {
- os.close();
- fis.close();
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- JOptionPane.showMessageDialog(null, "Sikeres feltöltés!");
- }
- }
- public void uploadSubtitle(File f){
- ftpUrl = String.format(ftpUrl, user, pass, host, "public_ftp/subs/" + f.getName());
- System.out.println("Upload URL: " + ftpUrl);
- try {
- URL url = new URL(ftpUrl);
- URLConnection con = url.openConnection();
- os = con.getOutputStream();
- fis = new FileInputStream(f);
- byte[] buffer = new byte[BUFFER_SIZE];
- int bytesRead = -1;
- while ((bytesRead = fis.read(buffer)) != -1) {
- os.write(buffer, 0, bytesRead);
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
- }finally{
- try {
- os.close();
- fis.close();
- } catch (IOException e) {
- JOptionPane.showMessageDialog(null, e.getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement