I have been having an FTP issue using the com.jscape.FileTransfer API that I haven't been able to make sense for quite sometime. Here's my code:
public void do FTPTest() {
FileTransfer f = protocol.equalsIgnoreCase("FTP") ? new FtpTransfer(ftpHost, userName, password, new Integer((int) port)) : (protocol.equalsIgnoreCase("SFTP") ? new SftpTransfer(
ftpHost,
userName,
password,
new Integer((int) port)) : null);
try {
f.connect();
f.setAuto();
System.out.println(f.getDir());
f.upload("test".getBytes(), "ktest1.txt");
} catch (Exception e) {
e.printStackTrace();
}
}
This code simply connects to an FTP/SFTP server and uploads a file called "ktest.txt"
My issue happens when I try to upload files to the base directory of the FTP/SFTP site.
Case 1: Connecting to FTP site 'A'
f.getDir() --> '/'
f.upload() --> SUCCEEDS
Case 2: Connecting to SFTP site 'B'
f.getDir() --> '/'
f.upload() --> FAILS (with permission denied error)
However,
Case 3: Connecting to SFTP site 'B'
f.getDir() --> '/'
f.setDirUp()
f.getDir() --> ''
f.upload() --> SUCCEEDS
Notice how it works when I do a setDirUp()
If i try to do the same on site A,
Case 4: Connecting to FTP site 'A'
f.getDir() --> '/'
f.setDirUp() (permission denied error)
All cases succeed if a do a setDir('testFolder') before uploading the file. i.e. a dir that is not in the base dir.
I don't understand how doing a setDirUp from '/' --> '' lets you upload a file to the base directory. What happens when you do an UP from '/'. What is '' ?
And how uploading to '/' works for some FTP sites.
BTW both FTP sites lets me upload files to the base dir without any issues using a client like WinSCP.
Could be that base dir / is not allowed for upload operation. When you do setDirUp() FTP server moves to back to default directory which is allowed for FTP transfer. Try to upload something to / with some GUI FTP client and see if it works.
Related
I tried to submit a flink job that is already packaged in a JAR. Basically it consumes a kafka topic protected by SASL authentication, thus it requires a .jks file which I already include them in JAR and read in the code as:
try(InputStream resourceStream = loader.getResourceAsStream(configFile)){
properties.load(resourceStream);
properties.setProperty("ssl.truststore.location",
loader.getResource(properties.getProperty("ssl.truststore.location")).toURI().getPath());
}
catch(Exception e){
System.out.println("Failed to load config");
}
I tried to submit the job on two different (different VM specs) standalone server for the sake of testing. One server runs succesfully, but another throw a java.nio.file.NoSuchFileException, saying that my .jks file is not found. Can someone please point out the possible issue on it?
Here, the flink is deployed on a standalone cluster mode with the following version:
Flink version: 1.14.0
Java version: 11.0.13
I realize my question was really silly. This part actually returns null and trigger exception.
loader.getResource(properties.getProperty("ssl.truststore.location")).toURI().getPath()
The problem was that I submit the job through web UI thus I couldn't see the printed message. Thus, the filename resolves to the original one stored under the configFile, which is a relative path. Why one machine works and another one doesn't? Cause I previously somehow has the .jks on my homedir for another testing :).
For others to not jump into this mistake, here is the summary of what will .getResource() resolve if run from IDE (gradle run task) and jar, respectively.
// file:home/gradle-demo/build/resources/main/kafka-client.truststore.jks
// jar:file:home/gradle-demo/build/libs/gradle-demo-1.0-SNAPSHOT.jar!/kafka-client.truststore.jks
System.out.println(loader.getResource("kafka-client.trustore.jks").toString());
// home/gradle-demo/build/resources/main/kafka-client.truststore.jks
// file:home/gradle-demo/build/libs/gradle-demo-1.0-SNAPSHOT.jar!/kafka-client.truststore.jks
System.out.println(loader.getResource("kafka-client.trustore.jks").getPath());
// home/gradle-demo/build/resources/main/kafka-client.truststore.jks
// null
System.out.println(loader.getResource("kafka-client.trustore.jks").toURI().getPath());
// file:home/gradle-demo/build/resources/main/kafka-client.truststore.jks
// jar:file:home/gradle-demo/build/libs/gradle-demo-1.0-SNAPSHOT.jar!/kafka-client.truststore.jks
System.out.println(loader.getResource("kafka-client.trustore.jks").toURI());
kafka-client:2.4.1
org.apache.kafka.common.security.ssl.SslEngineBuilder#285
try (InputStream in = Files.newInputStream(Paths.get(path))) {
KeyStore ks = KeyStore.getInstance(type);
// If a password is not set access to the truststore is still available, but integrity checking is disabled.
char[] passwordChars = password != null ? password.value().toCharArray() : null;
ks.load(in, passwordChars);
return ks;
} catch (GeneralSecurityException | IOException e) {
throw new KafkaException("Failed to load SSL keystore " + path + " of type " + type, e);
}
It looks like we should put jks file in file system(nfs or hdfs) where task manager can access by absolute path.
I'm trying to use the rename functionality and keep getting this error.
Stacktrace:
3: %RNFR-bad%
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1950)
...
Here's the method I'm using to move the file
private void moveFile(String sourcePath, String destinationPath) {
try {
System.out.println("Move: " + sourcePath + " to: " + destinationPath);
sftp.rename(sourcePath, destinationPath); //sftp = ChannelSftp
} catch (SftpException e) {
e.printStackTrace();
}
}
Here's the output for my println:
Move: /SND/OUTBOUND/TestOutboundFile1.txt to: /SND/OUTBOUND/PROCESSING/TestOutboundFile1.txt
I've tried some other options posted around on here (get then put, multiple connections, etc) but keep getting the same error or it just sits and hangs (this was happening with the get then put method). Everything I've seen on the web says this should be as easy as my method but I just can't seem to get it to work. Can't find anything with the "RNFR-bad" error that is useful either.
The destination directory already exists and it's empty. What am I missing? Any help much appreciated.
EDIT: This ended up being a permissions issue and the code posted above worked perfectly fine after the admin granted my account the correct permissions. I was able to create and delete both files and directories but was unable to rename files until account privs were modified.
3: %RNFR-bad%
SFTP error code 3 means "permission denied". This implies that you're getting an error because you don't have permission on the remote system to perform the file move operation that you're trying to do.
"%RNFR-bad%" doesn't seem to be meaningful. My guess is that the remote SFTP server is using localized messages and it doesn't have a proper message for this case, or it's malfunctioning in some other way.
I am new to FTPSClient i trying to connect to a FTPS created in my laptop. i don't exactly what some of the methods working and their parameter meaning.
For example,
In my code i have created a FTPSClient as below:
FTPSClient ftps =new FTPSClient();
Then connected to a server use connect() method with ip address.
ftps.connect("172.xx.xx.xxx");
After every step i will check the reply code using.
ftps.getReplyCode();
In the below code i know that
username = system username
password = the password to login
ftps.login(username, password);
In the my system in Internet Information Service(IIS). Created an ftp server with ssl and given the below directory to share.
C:\Users\karan-pt2843\Desktop\FTPS
Want to send the file in below directory to the server.
D:\sam.txt
Now i want to store a file in the server in the given above directory and i tried using
remote="";
local="";
InputStream input;
input = new FileInputStream(local);
ftps.storeFile(remote, input);
input.close();
I don't know what value to give for remote and local. please help me with the values to give on them and the what happens internal.
// Use passive mode as default because most of us are
// behind firewalls these days.
ftps.enterLocalPassiveMode();
...
String remote = "samFromClient.txt"; //Place on FTP
String input = "D:/sam.txt" //Place on your Client
//Your FTP reads from the inputstream and store the file on remote-path
InputStream input = new InputStream(new FileInputStream(input));
ftps.storeFile(remote, input);
input.close();
ftps.logout();
...
Taken from: Apache example
HI Friends I am working on a java application to store the file into the server
but when i upload some file its shows
org.apache.commons.net.io.CopyStreamException: IOException caught while copying.
QUIT
550 can't access file.
can any body tell me how to solve that?
public void uploadtxtFile(String localFileFullName, String fileName, String hostDir)
throws Exception {
FTPClient ftpclient= DBConnection.connect();
File file = new File(localFileFullName);
if (!(file.isDirectory())) {
if (file.exists()) {
FileInputStream input = null;
BufferedInputStream bis=null;
try {
input = new FileInputStream(new File(localFileFullName));
if (input != null) {
hostDir = hostDir.replaceAll("//", "/");
logger.info("uploading host dir : " + hostDir);
boolean bool =false ;
logger.error("Replay of the ftp store file is 1111"+ ftpclient.getReplyCode());
try{
ftpclient.enterLocalPassiveMode();
logger.error("Replay of the ftp store file is 2222"+ ftpclient.getReplyCode());
if( ftpclient.isConnected()){
// here server timeout error is get
logger.error("here server timeout error is get");//new
bis = new BufferedInputStream(input);
logger.error("Replay of the ftp store file is 3333"+ ftpclient.getReplyCode());
bool = ftpclient.storeFile(hostDir, bis);
} else{
logger.error("here server timeout error is get");//new
bis = new BufferedInputStream(input);
logger.error("Replay of the ftp store file is 6666"+ ftpclient.getReplyCode());
ftpclient.enterLocalPassiveMode();
bool = ftpclient.storeFile(hostDir, bis);
}}finally{
bis.close();
input.close();
}
logger.error("Replay of the ftp store file is 4444 "+ ftpclient.getReplyCode());
if (bool) {
logger.info("Success uploading file on host dir :"+hostDir);
} else {
logger.error("file not uploaded.");
}
} else {
logger.error("uploading file input null.");
}
} catch(Exception ex)
{
logger.error("Error in connection ="+ex);
}finally {
ftpclient.logout();
ftpclient.disconnect();
}
} else {
logger.info("uploading file is not exists.");
}
}
}
and also the response of file folder is not show
SYMPTOMS
When attempting to upload a file to a remote FTP site, a 550 error code is encountered, resulting in an error message similar to one of the following examples:
Example 1:
STATUS:> Transferring file "/pub/yourfile.txt"...
COMMAND:> SIZE yourfile.txt
550 yourfile.txt: No such file.
STATUS:> Requested action not taken (e.g., file or directory not found, no access).
COMMAND:> CWD /pub/yourfile.txt
550 /pub/yourfile.txt: No such file or folder.
STATUS:> Requested action not taken (e.g., file or directory not found, no access).
COMMAND:> STOR yourfile.txt
Example 2:
COMMAND:> STOR yourfile.txt
550 Permission Denied.
ERROR:> Requested action not taken (e.g., file or directory not found, no access).
CAUSE
Example 1:
In this example the 550 code returned by the remote FTP server is for
information purposes only. It is not an error and should be ignored
by the user. In this case an upload command has already been given
but before the upload can be started CuteFTP needs it determine
whether or not the file being transferred already exists on the remote
site as either a file or a folder.
First, the SIZE command is sent in an attempt to determine if a file with the same name exists on the remote site. The server
responds with a 550 indicating that the file does not already exist
there.
Next, the CWD command is sent in an attempt to determine if a folder with the same name exists on the remote site. The server
responds with a 550 indicating that a folder by that name does not
exist.
Finally, the STOR command is given and the file upload begins.
Example 2:
A file upload is being attempted but the remote server has denied the
needed permission. The 550 error code is a result of insufficient
account privileges on the remote FTP server. The error is not caused
by CuteFTP.
RESOLUTION
Example 1:
Not applicable. In this example the 550 code returned by the remote
FTP server is for information purposes only. It is not an error and
should be ignored by the user.
Example 2:
If you believe that your FTP account privileges or permissions are
configured incorrectly, contact the technical support department at
the remote FTP site or your Web hosting company for help.
Or you can check FTP "550 Access is denied" Error
When I try to connect our alfresco through SFTP it is not able to connect alfresco. It hangs the explorer and no error goes in the logger file also.
public void FTPTest()throws SocketException, IOException, NoSuchAlgorithmException
{
FTPSClient ftp = new FTPSClient("SSL");
System.out.println("1");
ftp.connect("172.17.178.144",2121); // or "localhost" in your case
System.out.println("2"+ftp.getReplyString());
System.out.println("login: "+ftp.login("admin", "admin"));
System.out.println("3"+ ftp.getReplyString());
ftp.changeWorkingDirectory("/alfresco");
// list the files of the current directory
FTPFile[] files = ftp.listFiles();
System.out.println("Listed "+files.length+" files.");
for(FTPFile file : files) {
System.out.println(file.getName());
}
// lets pretend there is a JPEG image in the present folder that we want to copy to the desktop (on a windows machine)
ftp.setFileType(FTPClient.BINARY_FILE_TYPE); // don't forget to change to binary mode! or you will have a scrambled image!
FileOutputStream br = new FileOutputStream("C:\\Documents and Settings\\casonkl\\Desktop\\my_downloaded_image_new_name.jpg");
ftp.retrieveFile("name_of_image_on_server.jpg", br);
ftp.disconnect();
}
I got output in our console only
1
at the execution of ftp.connect("172.17.178.144",2121); this code system will be hang no error got in our console
I am able to connect to my Alfresco through SFTP with the Filezila FTP client software. Can any one help me resolve this issue?
If I'm not mistaken then Alfresco chose for FTPS.
So try it with the following code here: http://alvinalexander.com/java/jwarehouse/commons-net-2.2/src/main/java/examples/ftp/FTPSExample.java.shtml