I'm trying to set up an Apache Mina FTP server in my continuously-deployed Java application. I'd like to be able to update and deploy it without users experiencing FTP downtime. I suspect this involves some sort of proxy (ProxyConnector?) to handle requests and delegate them between two copies of my FTP server. When a change is made, one copy should be updated and restarted before the other in order to maintain uptime.
I haven't been able to find any examples of this with Apache's Mina FTP server. Is this possible? Where can I find examples? Thanks.
You need a standard proxy server which listens to the two FTP ports and passes the connection to one of two FTP servers, you could even implement fail over or load balancing the proxy. The simplest TCP proxy just copies what ever it gets from one socket to the other in both directions.
The code is the same, regardless of what TCP server you are proxying or what software it uses.
Related
I want to listen any updates of the file system but on the client-side. I know that I can do the same thing on server-side via SftpEventListener but I'm not sure if there is any option to implement this on the client-side via the aforementioned listener or somehow else.
Is it possible to run class file which is on different system?
For instance,
I have 2 machines (server and client) and there are 2 java class files SocketServer.class and SocketClient.class in respective machines.
I need to run SocketClient.class from server machine to make connection establish between server and client. (Note: I should not run SocketClient.class manually)
Please advice?
Thanks in advance.
-Sithik
It is my understanding that the client generally makes the connection to the server to access resources on the server. In the past I have used an API to access resources on the server. Essentially I am not running the classes from the server directly I am using the API as a form of abstraction in order to handle the communication between the resources on the client side and server side.
I also mainly implement the Factory Design Pattern which may help you here.
http://howtodoinjava.com/2012/10/23/implementing-factory-design-pattern-in-java/
Ultimately your application should make requests of a server first and once a connection is established then the server will provide a response.
I succeeded setup a Java TCP server.
I succeeded setup a PHP TCP client. (By using stream_get_contents, fwrite)
The problem is, when I try to transfer my PHP TCP client to a hosting company (in my case GoDaddy.com), it doesn't work. GoDaddy probably blocks stream_get_contents.
What are my alternatives?
did you try your code locally? if it works locally maybe you should try these:
-fix firewall issue on JAVA tcp server machine
-check for NAT/PAT configuration
and if it still doesn't work,
I don't think you can communicate with other servers at socket level on hosting environments(not sure). but why don't you use web services?
Thrift provides several different non-blocking server models, like TNonblockingServer, THsHaServer, and TThreadedSelectorServer. But, I'd like to enable SSL on the server. It seems SSL only works on blocking servers in Thrift.
Anyone has any clues of a non-blocking SSL server in Thrift? Java example would be highly appreciated.
One alternative to worrying about SSL in your Java App is to stand up something like nginx (http://wiki.nginx.org/SSL-Offloader) as a reverse proxy.
This has the upside of your application not needing to care about SSL but does require one more layer in your stack.
Clients will connect to the nginx server instead of directly to your client and nginx will forward those connections to your Thrift server.
You don't necessarily need two different servers for this approach, just configure your Thrift server to only listen on localhost (127.0.0.1 for ipv4) and have nginx listen on your external interfaces and forward to localhost.
Edit: client -> server in last paragraph
I want to access to a file (read) that exist on a remote machine from my code JAVA,what I need to do that?
just the IP of the machine and the location of the file or I need somthing else?
Thank you
There are some choices:
Via a 'mapped' directory using SMB/Samba to the remote machine and you can then access the file using the normal File class.
Via a Web Server where read access is easier (if you require write access then you are looking at something like WebDAV). This requires the use of the HTTP protocol in your code.
Via FTP or SFTP network protocols to access the file. This obviously requires the use of (S)FTP classes to access the file.
The first option is easiest from a coding point-of-view.
If both the Java code and the remote file are on Linux machines, you can also choose NFS.
As always you need to start a server which serves the file - you need nfsd to share the directory containing that file on the remote machine.
On the machine where your Java code will run, mount the shared nfs
Here is a brief introduction of using nfs on Ubuntu.
If you prefer FTP/HTTP, you will be interested in Apache commons vfs library, which supports many protocols including FTP, SFTP, HTTP, etc.
First of all, you need a service on the remote machine that serves files. Once a file-serving service exists, you communicate with the service using its protocol.
Assuming the client-server model, you have several choices on the remote (server) side. First of all, you can design your own protocol, write a server, deploy it on the remote machine and write a client (in Java) which will talk with the server using the designed protocol. However, there many off-the-shelf solutions (protocols + servers + Java client libraries) that might be used. Three protocols which come to mind right now: TFTP, FTP and SMB.
If your aim is simplicity, I recommend TFTP: there are free TFTP servers for UNIX, Windows and Mac OS X, and there is Apache Commons Net Java library on the client side.