英文:
Java - Using JSch but getting an error when trying to move a file on FTP - %RNFR-bad%
问题
我尝试使用重命名功能,但一直收到以下错误。
堆栈轨迹:
3: %RNFR-bad%
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1950)
...
以下是我用于移动文件的方法:
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();
}
}
以下是我的println输出:
Move: /SND/OUTBOUND/TestOutboundFile1.txt to: /SND/OUTBOUND/PROCESSING/TestOutboundFile1.txt
我已经尝试了一些在这里发布的其他选项(先获取再放置,多个连接等),但仍然收到相同的错误,或者程序一直停在那里不动(使用先获取再放置的方法时出现了这种情况)。我在网上看到的所有信息都说这应该像我的方法一样简单,但是我似乎无法使其工作。关于"RNFR-bad"错误,我找不到有用的信息。
目标目录已经存在且为空。我错过了什么?非常感谢任何帮助。
编辑:最终发现这是一个权限问题,在管理员授予我的帐户正确的权限后,上述代码运行得非常好。我可以创建和删除文件和目录,但在帐户权限被修改之前,无法重命名文件。
英文:
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.
答案1
得分: 1
3: %RNFR-bad%
SFTP错误代码3表示“拒绝许可”。这意味着您因为在远程系统上没有执行您尝试进行的文件移动操作的权限而收到错误。
“%RNFR-bad%”似乎没有意义。我猜测远程SFTP服务器正在使用本地化消息,并且对于这种情况没有适当的消息,或者它在某种其他方式下发生了故障。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论