This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!

Felix Wong

Greenhorn
+ Follow
since Feb 13, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Felix Wong

I created a program via JSch to upload files to a Linux host via SFTP. After uploading, I will use ChannelExec from JSch to pass 'md5sum' command to the destination Linux host to get back the checksum of the file I just uploaded so that I can verify the integrity.

Now for some reason the Linux Host will be replaced by containers. For this, I created a SSHD program by Apache mina running on a Pod to perform the same function of SFTP. Now I can upload files to this SSHD program, but I am not able to send the 'md5sum' command now.

I tried to research a bit and it seems like I need to implement a commandFactory to take care of this. However I could not find any example or hint how exactly I can implement it. May I know if anyone has clue on this?

Thank you very much.

4 weeks ago
Thank you very much!! This is exactly what I need!! I'm trying to implement methods I need.

Ron McLeod wrote:I've never used Apache Mina SSHD, but it looks like you can add a SftpEventListener to the SFTP subsystem and hook all kinds of events:

4 weeks ago
I am using Apache Mina to setup an SSHD server. It is running fine but I only have authenticated logs once users logged in. How can I implement user action logs such as uploading/downloading and file information such as name/size?

Below is my code:

This is the only authenticated log I can have.
1 month ago
Thanks for your reply! With your example, I can manage to make my own one work as well. I just need to modify the delay time of createFileInWatchedFolder from 500 to 1500 so that my program can pick up the file and start its tasks.

However, there is an issue on the tearDown(). I will get illegalStateException on executor.shutdownNow(). If I modify to executor.shutdown(), the exception will be gone. It seems to me that shutdownNow() will forcibly shutdown all tasks while shutdown() will initiates an orderly shutdown. The assertion still works for both, is there any difference in my case when I use these 2 methods?
1 month ago
Thanks for reply. I tried too but somehow test class does not end and tearDown() does not run. I saw from debug window that the main thread is still running and I believe that's why. Below is my code now.



Stephan van Hulst wrote:

Stephan van Hulst wrote:If your main methods keeps blocking after the file has been uploaded because it is waiting for the next file to upload, then you should schedule it in the background as well

1 month ago
I tried to put logging in every method and the scheduled task, but nothing prints out.

After a few tries, I managed to use below code to run. All methods in the test class and the main application are launching in the expected order. However, there are a few issues.
1. I need to take out @SpringBootTest and kick off the main on my own. If I have that, the main will just launch and it blocks everything in the test class.
2. Although it is now running the main first, creating a file in the watching folder, and doing its tasks of uploading and deleting, it is not asserting. I can see from console it can get into assertThatFileIsUploadedAndDeleted(), but the test class does not end. The main is still holding it.
3. As mentioned in point 2, the tearDown() never runs.

1 month ago
Thank you for the reply. I tried to implement your solution and have below codes. The test class could start and I see the program is running, but the file is not creating. If I put some files in the watched folder manually, the program works.

What goes wrong with my code?



Stephan van Hulst wrote:Welcome to CodeRanch!

From your test method, schedule a background task that creates a file in the watched directory. Then call the main method:

You may need to increase the initial delay before the scheduled task is executed if the main method needs more than 500 milliseconds to set up the file watcher.

1 month ago
My application has to watch for any file created in a folder, upload that to a SFTP server and delete afterward. I use watch service to achieve this implemented some codes in the main method.

I try to develop integration tests with JUnit. My issue is that once the program starts, it will be locked by the watch service, and no codes in the integration test will be run. Is there any way I can create integration tests?

Thank you very much.
1 month ago