I want to write a FTP-Client in Java with a restriction: No advanced libraries (e.g. .ftp, .url etc.) allowed.
How do I implement a method to print the current directory, change directory and download a simple .txt-file?
You can start by reading up the RFC governing the FTP protocol. With that you can get an idea on how the FTP protocol works, how it sends commands, expected responses etc.
You can find a link here: https://www.rfc-editor.org/rfc/rfc959
Aside from that you can have a look at this GitHub repository. In there you'll find a simple FTP client that I wrote back when I was in uni. The FtpConnection class implements most of the commands you'll need to do your job.
Have a look at it and how these are used.
https://github.com/Kortex/Simple-FTP-Client
Related
I have two java libraries.
One connects to DHT and can successfully download torrent files.
And the other which downloads the actual data associated with the torrent.
The torrent client library expects an announce or announce-list section in the torrent, and does't understand the 'nodes' entry.
The question is how do I alter the torrent client code to understand the 'nodes' section of a torrent file.
OR
How do I calculate a tracker URL from a set of ip:port DHT peer addresses?
I could just guess the url by guessing a port number and appending /announce onto it.. but this surely isn't right?
Does anyone know how this works?
For DHT-only operation you do not need an announce URL. If the library itself expects one you can insert a dummy url, the format dht://<infohash in hex> is common, but it does not matter, as it won't be used.
The DHT part on the other hand does not require the nodes to perform a lookup, it simply operates based on the infohash of the torrent. The nodes can optionally be injected into a dht client for bootstrapping, e.g. by executing a ping on them, but that should not be needed if it already is bootstrapped.
Once the DHT client has done its get_peers and announce lookups the peer lists can be injected back into the torrent client.
Since you're using my library: You can use PeerLookupTask to read a torrent peer list from the DHT and AnnounceTask to add your torrent port to the list. The obtained IP and Ports have to be passed to the torrent client. The GetPeers CLI command contains an example how to use the first part.
There also are utility methods that should cover common use cases.
For an alternative I may recommend you to see Bt, which is a Java 8 BitTorrent client and already integrates with the8472's mldht: https://github.com/atomashpolskiy/bt
I have a requirement where I intend to build a tool to scan the email contents including the attachments. The email servers is either going to be SendMail or z/OS Communication Server, both support SMTP. The sever is not Miscrosoft implementation so MAPI or Outlook API is not there into picture. The tool would be Java based code and basically need to look for contents that are not-permitted based on some rules. What are my options here? There is the possibility of using a proxy server but we are looking for a more direct approach.
The z/OS Communication Server SMTP implementation has a built-in "exit" capability - see http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/F1A1B4B0/30.3?DT=20110609204120#HDRWQ1299.
The exit is called for just about any SMTP activity and it can examine, change or reject just about anything based on the rules you establish. It is generally written in IBM Assembler Language, but there's no reason you couldn't have a thin assembler layer that passes data to a Java app using whatever protocol you like (say, a pipe or a socket).
There are many little details to handle, such as character encoding (EBCDIC vs. ASCII or UTF-8, for example) plus weeding out attachments from email content. But using the exit preserves all the z/OS specific features of IBM's SMPT server without trying to recreate any of that yourself.
Good luck!
I need to query a nrpe nagios server from a Java application remotely just as check_nrpe would do:
check_nrpe -H 192.***.***.*** -p 56** -c "check_load"
When I say "from a Java application" I mean I want the results to be received and processed at my Java application. The first idea I had was to call the "check_nrpe" command from my application and retrieve its output and return value but I would like more a standalone solution where no external programs are called.
I don't need to wait for state changes, just eventually check the monitor state. Since I have been unable to locate any Java library (should I try JNRPE?), I would like to implement the protocol check_nrpe and nrpe daemon use to communicate.
Have any of you tried this before? In that case, do you have a description of this protocol?
If your answers are negative I will try to analize the protocol using whireshark but any clue will be much appreciated.
An explanation of NRPE protocol from Andreas Marschke blog, The NRPE Protocol explained (on gitHub too)
Anyway, JNRPE have a full working implementation of the protocol, you can download jcheck_nrpe-2.0.3-RC5 source code and take a look at jcheck_nrpe-2.0.3-RC5\src\main\java\it\jnrpe\client\JNRPEClient.java class for a sample client who's using jnrpe-lib-1.0.1-RC5.
jnrpe-lib have two concrete classes which implements the protocol request and response
JNRPERequest.java
JNRPEResponse.java
The full protocol implementation classes can be found at jnrpe-lib-1.0.1-RC5\src\main\java\it\jnrpe\net\ folder
I'm writing an FTP server with Java, and now I want to answer to LIST command.Sending only file names is enough, and I don't need to send file size, owner, permission, etc. It seems that just sending some strings, as file names, does not satisfy the client (I tried both ASCII and binary formats). How can I find out what does an FTP client expect as a reply?
I'm testing my server using FireFTP and FileZilla
If you want to create a compatible FTP server, you need to handle LIST and NLST (standard commands) and also MLST and MLSD extension commands.
Format for LIST command is not defined anywhere and there are about 400 formats encountered in the world. Using Unix ls format or Windows DIR format would work with most clients as these are formats quite widespread and well supported by the clients.
NLST is the list of file names only.
MLST and MLSD use the machine-parseable format (this is what M letter stands for) which is described in RFC 3659. It's easier for the clients to handle and it's support is very welcome.
The canonical place to look is the relevant RFC: http://www.ietf.org/rfc/rfc959.txt
Unfortunately, in this particular instance the RFC is pretty vague:
Since the information on a file may vary widely from system
to system, this information may be hard to use automatically
in a program, but may be quite useful to a human user.
In order to ensure compatibility with existing FTP clients, your best bet is to look at some widely-deployed FTP server software and emulate the format of its output.
How does one parse the mail files generated on a Linux system using Java? I mean, I want to be able to extract the From, To, Timestamp and Subject of the various emails inside the file. Any suggestions?
javax.mail.internet.MimeMessage.parse(InputStream)
it's protected but you can subclass it to use the method. However, the file format is quite simple, if you just want some headers, why not parse it on your own?
Those files belong to the Mail Transfer Agent and maybe the user's mail client. Other programs should tread very softly or better yet keep out altogether. Or is your program a mail client?
The "clean" way to do this would be to open up an SMTP or IMAP connection to the mail server / MTA and ask it for pieces of mail on behalf of your user, using his credentials that he gives you.
There's a Java mail API for this that knows how to do this well: http://java.sun.com/products/javamail/ .