Zipping a directory to a remote location in Java - java

I'm trying to create a zip file from a directory in Java, then place that file on a remote server (a network share). I'm currently getting an error because the Java File object cannot reference a remote location and I'm not really sure where to go from there.
Is there a way to zip a directory in Java to a remote location without using the File class?

Create the ZIP file locally and use either commons-net FTP or SFTP to move the ZIP file across to the remote location, assuming that by "remote location" you mean some FTP server, or possibly a blade on your network.
If you are using the renameTo method on java.io.File, note that this doesn't work on some operating systems (e.g. Solaris) where the locations are on different shares. You would have to do a manual copy of the file data from one location to another. This is pretty simple using standard Java I/O.

Related

Android NFS Client

I have found a good library to implement an Android NFS Client 'nfs-client-java', I'm creating an Nfs3 Client and I can access files and create new files... on the server. But the problem is that I can't mount the whole shared directory from the server. On Linux NFS Client, I can specify the mount point with
mount -t nfs -o nolock,rw,vers=3 192.168.1.10:/media/user/ /mnt/media_rw/remote
where /mnt/media_rw/remote is where the shared directory will be mounted.
My question is: How can I achieve the same result on Android App ?
In Android app development, there's no mounting at the Linux vfs layer. So you wouldn't be able to achieve exactly the same result.
There closest thing I'm aware of is the documents provider system https://developer.android.com/reference/android/provider/DocumentsProvider. From the documentation:
A document provider offers read and write access to durable files, such as files stored on a local disk, or files in a cloud storage service.
You'd implement methods such as openFile in your NFS documents provider by, for example, downloading a copy through the library you found, opening it, and forwarding a parcelable file descriptor in the return value.

Connect to a shared drive in java

I need to connect to a windows shared drive so I can make a directory and then some files in that directory. I am not sure how I would go about this. Can you use any built in classes for java?
If you map the drive onto your machine you should be able to access the drive with the normal filepath "(Drive Letter):/"
Depending on your network configuration you might also be able to use the filepath "\(Server name)\"

where to keep the file path while hosting the java web app?

I have developed a website, one of its operation is to read and write data to text files stored at my local machine such as D://test.txt or C://file.txt, but now I am going to host my website at the external server, i mean over the internet use, i wonder where to keep these files that are associated with read and writing operations. At present I am getting an exception file not found if i am using my local machine location. For your information, I am using GlassFish server.
You will want to create a system property on Glassfish, which represents the file path and name. Then upload the file to that location of your choosing on the server where your website application is deployed.
Depending upon your needs, you may find it easier to deploy the file out with your application. Make sure the file is on the classpath, and you can load it using any number of ways.

Upload a file by FTP at a specfic location

FTP client class is not connecting
further to this link i just want to know to upload a file in specific directory location for example there is a cross reference in IP and then further a library in cross reference then how would i upload file in library or in precise how would i get connected to ip/cross reference/library for location where i need to upload a file. here i want to mention that i successfully get connected to IP till now.
The constructor of FTPHTTPClient doesn't appear to take a path in the constructor, its just the hostname/ip. Also, most FTP clients use / and not \ as the path separator.
The JavaDoc for FTPClient shows there is a method changeWorkingDirectory(String pathname), which I am guessing is what you want to do.

FTP Upload directory tree in java

Is there any library that supports uploading directory tree in remote server ?
You can always use the org.apache.commons.net.ftp.FTPClient client and recursively upload all files in your directory.
The Apache Virtual File System (VFS) project can do this, whilst abstracting the details of dealing directly with FTP connections.

Categories