Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2012, 02:26 PM   PM User | #1
david.ginn524
New Coder

 
Join Date: Oct 2011
Posts: 28
Thanks: 2
Thanked 0 Times in 0 Posts
david.ginn524 is an unknown quantity at this point
connect and forward ftp connections

Ok well I posted this idea in my raspberry pi forum but there is not enough of a support base yet i think to help me with this. I have a small raspberry pi computer which runs a version of debian. Below you will find my original description
Quote:
Ok I have an idea that I have been wanting to implement but not entirely sure how to. Here is a basic description.
I have a server that gets used for downloading files where ever i want. It's like dropbox but my own personal one. Unfortunately me keeping it on 24/7 is a lot of electricity/money. I ordered a pi thinking I can do this which i am hoping it is possible. My server is just a giant ftp server.

My idea: If no one is connected it goes to sleep to save power. then when someone tries to connect it starts up and lets the person in.
Since Rpi's don't use much I chose this as a viable option to run 24/7. My plan is to create a script /ftp server on the Rpi. When someone tries to connect the Rpi see's that catches the connection and tells my server to wake up. While it is doing that it "holds" the connection then once the server is up it will forward the connection to the server as if it was on originally.
Hopefully this makes sense? yes?

Right now i have scripts in place on my main server that checks every 5 min to see if someone is connected if not it goes to sleep
I also found an article on how to use the Rpi's GPIO pins to turn on a LED which is written in python.
http://tinyurl.com/7ww3gkw
This is why i posted it in here. In theory I just have to modify the code a tiny to have it turn on my server via the regular power button.
I can easily setup an ftp server on the RPi.

The problem I have is, I have no clue how to "hold" the connection of the incoming FTP then forward it.
There are a few requirements for this pretty much as I see it.
1 it has to accept any ftp connection with any username and password
2 once it runs the script to power on the server it has to check to see when it is ready
3 while its powering up it has to "hold the connection"; maybe give a message say please wait.
4 once it's up and running it has to take the existing connection and forward it to the FTP server; then the other FTP server will check the username and password and continue like it was never off.
5 if the server is already on the RPi should automatically forward the connection without a message /run the scripts

Do you guys have any suggestions on how to even start the FTP section? I think I can manage with the turn on part/script through the GPIO pins
Currently I have the script to turn on my server and turn off my server. The turn off script is actually on the server and the turn on is on the raspberry pi.

Someone suggested essentially an echo server. So I decided that java is universal (i think?) I will write it in that. When normally I write things in PHP but can't really do that with this type of project.
Currently I have a "echo server" that can run in my eclipse

I am able to telnet into it at a specified port and type w/ then it writes it to a log. A few things that I don't know are
1: when I run it the first line will always have "ÿûÿû ÿûÿû'ÿýÿûÿý" in front of it then what ever i type. So example if I type hello for the first time upon connecting it will have "ÿûÿû ÿûÿû'ÿýÿûÿýhello" if i type hello again, it will show up just "hello"

i am not sure what that is. I am guessing that it would be because either 1 its null or 2 that is what telnet sends to connect to the socket. At any rate is there anyway to clear/flush this?

2 I have tried to look up some java ftp libraries but all i find are client libraries is there any libraries out there that you know of that I could use? because when i try to connect to the socket via FTP it times out because it doesn't get a response. (obviously since i haven't set it up.)

Code:
import java.net.*;
import java.io.*;
 
public class PortMonitor {
 

    public static void main(String[] args) throws Exception {
 
        //Port to monitor
        final int myPort = 1901;
        ServerSocket ssock = new ServerSocket(myPort);
        System.out.println("port " + myPort + " opened");
 
        Socket sock = ssock.accept();
        System.out.println("Someone has made socket connection");
 
        OneConnection client = new OneConnection(sock);
        String s = client.getRequest();
 
    }
 
}
 
class OneConnection {
    Socket sock;
    BufferedReader in = null;
    DataOutputStream out = null;
 
    OneConnection(Socket sock) throws Exception {
        this.sock = sock;
        
        in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
        out = new DataOutputStream(sock.getOutputStream());
     
    }

    String getRequest() throws Exception {
        String s = null;
        
        while ((s = in.readLine()) != null) {
           
       
            FileWriter fstream = new FileWriter("log.txt",true);
             BufferedWriter out = new BufferedWriter(fstream);
           System.out.println("got: " +s);
           out.write(s);
        
            out.close();
        
        }
       
        return s;
        
    }
}
any suggestions anyone?
david.ginn524 is offline   Reply With Quote
Old 09-29-2012, 10:19 PM   PM User | #2
renter
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
renter is an unknown quantity at this point
Why not just run the server on the raspberry pi? An idea you could try is to run a ftp server on the raspberry and a samba server on the other computer.
On the raspberry have your main ftp directory as /samba. Then when the main computer turns on your samba server will start and thats where you files will be pulled from.
Just have a ftp banner saying refresh in 30 seconds. Then write a bash script to monitor the connection log. When someone connects it checks to see if the server is on if not it runs your power on command which will then start you samba server.

[ADD]
You could do all this with bash.
renter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:41 AM.


Advertisement
Log in to turn off these ads.