Java upload files to remote linux server WITHOUT ftp or scp - java

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/

Related

WebDAV authentication through Java

I've made a program which copies files from phone to windows folder. Connection to phone via WebDAV server. The problem is that I cannot connect to phone through Java until I open for ex. htpp://192.168.1.40:8080 in my windows explorer. After that phone is visible in Java. But that ruins all the meaning of my program.
Does anyone knows how to get access to phone through Java in the first place? Do I need to change something in registry or?
Thanks a lot!
P.S. copying procedure goes by:
File src = new File("\\\\" + address + "\\DavWWWRoot\\DCIM\\Camera");
where address is "192.168.x.xx:8080"
and then it goes to Files.walkFileTree to copy all the files.
You have to use a WebDAV client if you do not want to rely on the OS. I suggest Apache Virtual Filesystem (VFS). It provides an additional layer over different types of filesystems and seems to have also support for WebDAV.
https://commons.apache.org/proper/commons-vfs/index.html
Well..I've made a bit different but most simplest way to solve my problem.
The whole problem was in this goddamn Windows OS. It has WebClient service on demand by default. I switched it to auto and now I can connect to phone (or any other WebDAV server) after reboot.
CMD code to switch to auto WebClient service:
sc config webclient start=auto
Run as Admin.
P.S. But I have to admit that my way (walkFileTree) to copy files from WebDAV server may be way far from the optimal.

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

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?

Write file to another UNIX server

Currently I am using weblogic for application server and it is running in one machine. I have to write the pdf(or any file type) to another Unix server. Can anyone please help me find the solution.
One solution is to mount the remote directory to your local server via smb or NFS (keyword sharing). Then you don't have to put any code for the copy job into your application. Instead the operating system will take care for the operation.
A simple and raw solution would be a SSH connection. There exists several Java libraries for SSH such as http://www.jcraft.com/jsch. Open a connection, write your file, close the connection. Of course you need the corresponding SSH keys and privileges to do this on the remote machine.

how to automatically and periodically upload a file from a windows machine to a unix server?

i have 2 csv files on my windows machine that i want to transfer to a unix server every hour (because the 2 files are updated every 30min).
so i search on the web and i found this possibility: to ftp the files from windows to unix using a batch and task scheduler.
i want to know if it's possible to do it from the unix server with a cron job or with java timer and not from the windows machine and if if there's other easier solutions.
thanks for your help
The main problem you would have is in allowing the Unix machine to access a Windows file.
You didn't specify what kind of networking configuration you use and what version of Windows it is, as some later versions provide facilities for file sharing across platforms.
In the worst case, you could set up an FTP (or SFTP) server on your windows machine, share a specific directory in which you will put the file, and then write a script on the UNIX that will download the file from the windows machine. A variation on this is to install a web server on the windows machine, and have the script on the unix make an HTTP request for the file.
You could install a webserver like http://www.aprelium.com/abyssws/
It seems to be free and should be not that hard to set up. Afterwards put your files in the htdocs-folder and configure your Vista-firewall to let requests on port 80 pass.
Then you can access your files via
http://IPofYourWindowsComputer/yourfile.zip
If you want to access your windows machine from outside your local network you'd have to setup your router to forward port 80 to your windows machine. Otherwise the machine from outside will be blocked by the router.
PS: Samba (SMB) just works within the same LAN. If you are you could create a shared folder and put the files in there and access them via smbclient or mount.
PPS: Maybe your question is better placed # http://serverfault.com

Categories

Resources