Testing a ftp client program in Java - java

I have a java app that reads files kept on a remote server using ftp protocol, I used the org.apache.commons.net.ftp.FTPClientto write my ftp client side code, but I dont know how to test it.

I know this answer is a bit late, but if you want to test FTP client code, then take a look at MockFtpServer (http://mockftpserver.org).

You can test by putting logs after connect, login, listing files etc, and in catch block you print the stack trace until all your connections issues are resolved.

Related

How to download remote files in Java

There are some posts regarding how to read from/write to a file in a remote system. However, I haven't found one useful to my purposes and I hope you can help me out.
So far, I have a java program that can connect to a server using sockets. The remote system (server) is not in the LAN which I think makes it more complicated to access files in that computer. The purpose of my "networking program" is to download files that are in the remote server and I can achieve this by copying bytes of the file once I have reached it, but I don't know how to "navigate" through the directories of the server. The only thing I've done so far is to connect to it.
The remote server runs on Linux. I'm trying to find out how to do this and I came across with JSch. I have not read too much about it but I would like to ask you if this is possible with JSch or what is the solution you would use.
JSch can surely work.
Refer this: File download

javasocketbridge - client not reading / java.net.SocketPermission

I am trying to achieve a TCP connection between a JavaScript client and a java server. (implementation must be this way I cannot swap to node for the server for example ).
Web sockets implmentation in java looked very complicated. I had a look at Jetty and JWebSocket and was quickly scared off. I have no idea what is going on in the source for them. – So I didn’t have much luck implementing a server using them.
So then I looked for websocket alternatives.
I noticed SocketBridge, It seems very straight forwards and offers exactly what I need for my project so I downloaded that.
I created a simple java server that just prints what I receives and sends a string as bytes back. I used the prebuilt JavaSocketBridge and modified the index.html to point to my server. My server recived the message but nothing showed up on the client.
function run(){
socket_connect('localhost', 31113);
socket_send("Hello from JavaSocketBridge applet");
}
I then decided to build the JavaSocketBridge to see if I could debug the read methods. However my build of JavaSocketBridge refuses to connect with the error.
Java Socket Bridge ERROR: Could not connect to localhost on port 31113
Access denied (“java.net.SocketPermission” “127.0.0.1:31113” “connect,resolve” )
(This was in chrome but it happens in firefox too)
So my questions:
Why does my build get a socket permission error?
Why does the client not receive anything even though the example does from google.com:80?
Notes.
My server appears to be working fine. (I have used a simple java client to test it.
I have used java 1.6 and 1.7 to build the JavaSocketBridge)
I have included C:\Program Files\Java\jre7\lib\plugin.jar
My System is Win7 64 and java SDK / JRE is up to date
Edit. Ive gone back to jetty and got a client/server working, however I will monitor this question.

Java server software not recieving connections when compiled to executable Jar

I have written code for a tcp (SSL) server which receives client connections and distributes data to the clients. the server GUI is based on JavaFX. When i run the server software from within Net Beans or Eclipse it works fine, receives client connections and sends and receives data. But when i compile the code into an executable Jar the server does not receive connections and client code throws: Connection refused exception.
I have tried pinging the server and it seems the server does not listen to the specific port when it is run from the executable Jar but DOES when run from within the IDE.
to be honest , I have no idea what could be causing this behavior. would appreciate any insights , suggestions or leads into how to fix this issue. I dont think the specific code is relevant but if somone thinks it is i will post the server code.
Well, turns out the problem was that the relevant keystores were not being loaded right. They were being loaded as FileInputStreams which will not work when embedded inside a Jar file.
I reverted them to being loaded as InputStreams , which work just as well with the SSL context and everything seems to be working right now.
Thanks a bunch for all the suggestions they defiantly helped me eliminate things along the way.

How can i upload file in remote machine(LAN) using java

How can i upload file in remote machine(LAN) using java program.I want to connect remote machine in LAN and upload file from my local machine to remote machine.So please tell me how can i do this.
I suggest you use JSch. You'll be able to connect easily to a remote machine and it allows you to execute file transfer using sftp for example.
It's hard to find a real documentation for JSch, but the various examples they give on their site are really complete and in general sufficient to help one succeeding in his task.
You probably want an HTTP client library for Java, to issue an HTTP POST request. (I assume the remote machine has some web server to upload the file).
Google gives several suggestions, like Hc.Apache

Java upload files to remote linux server WITHOUT ftp or scp

I am trying to write a program in java to upload some files from my local environment to a remote server. I cannot use FTP because there is no FTP server installed on that instance. Also port 22 is closed so I can't use scp either.
Is there any other way to approach this?
Thanks in advance guys!
You need something on the serverside, a program, which is waiting for your file. You can't just send something there.
An open port is always a program running, waiting for a connect.
So a couple of possible protocols are rsync and WebDav. But at the end of the day I recommend one of two options. Get ssh installed, or use rsync.
Talk to the unix admin and work something out.
Even linux servers sometimes use smb/cifs (the Microsoft technique to share files and folders) to publish data. The samba team provides a 100% Java library to access those: http://jcifs.samba.org/

Categories

Resources