mahesh
mahesh

Reputation: 1633

how to check if FTP path exists and writable in java

I would like to check the below in my java spring project.

Ftp path:-

ftp://mmepx/gpi/nsdsdfdt/fromDIR

1) I want to check if the above mentioned FTP path is working and accessible for writing in that folder "fromDir

I am using JDK1.6 and spring.

Appreciate any help.

Thanks

Upvotes: 1

Views: 1049

Answers (1)

user2864740
user2864740

Reputation: 61865

Use an FTP client/library and try the desired operation, such as PUT'ting a file. If it doesn't work, well - the resource (server, path, etc) didn't exist, wasn't writable, or otherwise wasn't accessible.

FTP doesn't allow a way of querying if a directory is writable or if an operation is allowed, other than trying it. And without actually using FTP, there is no way to tell if the URI is even "valid" for such use.

A common library used is Apache Commons Net (which includes FTP support), but it may be possible to use URLConnection for a simple upload as discussed here.


An aside:

If it is at all possible to avoid FTP, do so! A "drop in" replacement is SFTP, which uses the much more secure SSH stack.

Upvotes: 1

Related Questions