Java uploading file to AWS EC2 server - java

our use case needs to upload file from our on-premise server to an AWS EC2. Tried doing some research and could not find any available code samples on how to do this in Java. Has anyone done this before? and if yes and you direct me to some code template or sample codes I can use as basis.
We are using Java 8 by the way. Our EC2's VPC is connected to our on-premise network so for sure our on-premise server can see it.

If you don't have any specific services installed on your EC2 instance and want to push files to EC2 (instead of pulling from other services like S3), you could transfer files using the SSH protocol.
You can use jsch which is a Java library that implements SSH. There are many examples on the jsch website showing how to use jsch, also specific ones showing file transfers.

Related

how to change ebs volume inside .property file

i am new in aws. i created one ec2 instance and installed tomcat7, deployed java web application. after i want change inside my application like db.property file. how to change through java api.my all files are available in ebs volume. how to get particular file and modify and update through java programmatic.
Thanks,
Sriram
The AWS API doesn't let you access EBS volume contents directly. You need to log into the machine and make the changes.
If it's a Linux machine, you can do so via SSH.
You can use a command-line SSH client or an SSH client library, such as Jsch for Java.

Transfer file of size 300 MB - 1 GB from client to server using java application

I am trying to develop a desktop based application which will have a browse button. Once a file is selected by "Open File" dialog. The file should be sent to server(target) machine.
I am unsure of how this can be achieved in java. After searching through internet i found out that. This may be achieved in different ways. Some of them
Use FTP commands.
Socket Programming.
Third party library.
I do not want to use option 1 i.e., FTP because of security. Kindly guide on how this can be achieved ?
If you would like to use FTP, but it does not fit your needs concerning security, you could switch to Secure FTP (sFTP).
A library offering SFTP file transfer for Java is JSch. Example code for an sFTP transfer and even for a secure copy (scp) is available on the JSch webpage.

SFTP to FTP bridge

I would like to connect with an SFTP client to an FTP server using java. I know the two technologies have nothing to do with each-other. What I'm trying to accomplish is to connect to an FTP server via the internet with out using two ports or changing the server configuration.
Is there any SFTP->FTP bridge in java it would be great. If not, how can I accomplish that ?
I would like to incorporate this in an exciting java server so hence, java based solutions are preferred. If there is some standalone software which you can control via code than it should support windows and *nix.
(Since SFTP is just the means here, a similar WebDav solution will also work)
You could go with trial and error. Try this out see if it works.
How to retrieve a file from a server via SFTP?

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

How can I access to a file exists on remote machine?

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.

Categories

Resources